|
2 | 2 |
|
3 | 3 | <!-- end auto-generated rule header --> |
4 | 4 |
|
5 | | -Disallow `action` attribute on submit buttons. |
| 5 | +Disallow click action on submit buttons within a form. |
6 | 6 |
|
7 | | -Using the `action` attribute on submit buttons is a common mistake. Instead, you should use the `{{on}}` modifier to handle click events, or handle form submission at the form level. |
| 7 | +In a `<form>`, all `<button>` elements with a `type="submit"` attribute (or no `type`, since buttons default to `type="submit"`) should not have any click action. The action should be on the `<form>` element instead of directly on the button. |
8 | 8 |
|
9 | 9 | ## Rule Details |
10 | 10 |
|
11 | | -This rule disallows using the `action` attribute on `<button>` elements (which default to type="submit") and `<input type="submit">` elements. |
| 11 | +This rule disallows: |
12 | 12 |
|
13 | | -## Examples |
14 | | - |
15 | | -### Incorrect ❌ |
| 13 | +- Using `{{action}}` or `{{on "click"}}` modifiers on submit buttons inside a `<form>`. |
| 14 | +- Using the HTML `action` attribute on submit buttons or `<input type="submit">` elements. |
16 | 15 |
|
17 | | -```gjs |
18 | | -<template> |
19 | | - <button action="save">Save</button> |
20 | | -</template> |
21 | | -``` |
| 16 | +## Examples |
22 | 17 |
|
23 | | -```gjs |
24 | | -<template> |
25 | | - <button type="submit" action="submit">Submit</button> |
26 | | -</template> |
27 | | -``` |
| 18 | +### Incorrect |
28 | 19 |
|
29 | | -```gjs |
30 | | -<template> |
31 | | - <input type="submit" action="go" /> |
32 | | -</template> |
| 20 | +```hbs |
| 21 | +<form> |
| 22 | + <button type='submit' {{on 'click' this.handleClick}} /> |
| 23 | + <button type='submit' {{action 'handleClick'}} /> |
| 24 | + <button {{on 'click' this.handleClick}} /> |
| 25 | + <button {{action 'handleClick'}} /> |
| 26 | +</form> |
33 | 27 | ``` |
34 | 28 |
|
35 | | -### Correct ✅ |
| 29 | +### Correct |
36 | 30 |
|
37 | | -```gjs |
38 | | -<template> |
39 | | - <button {{on "click" this.handleClick}}>Save</button> |
40 | | -</template> |
| 31 | +```hbs |
| 32 | +<form> |
| 33 | + <button type='button' {{on 'click' this.handleClick}} /> |
| 34 | + <button type='button' {{action 'handleClick'}} /> |
| 35 | + <button type='submit' /> |
| 36 | + <button /> |
| 37 | +</form> |
41 | 38 | ``` |
42 | 39 |
|
43 | | -```gjs |
44 | | -<template> |
45 | | - <button type="button" action="doSomething">Click</button> |
46 | | -</template> |
47 | | -``` |
| 40 | +Buttons outside a `<form>` are allowed to have click actions: |
48 | 41 |
|
49 | | -```gjs |
50 | | -<template> |
51 | | - <form {{on "submit" this.handleSubmit}}> |
52 | | - <button type="submit">Submit</button> |
53 | | - </form> |
54 | | -</template> |
| 42 | +```hbs |
| 43 | +<button type='submit' {{on 'click' this.handleClick}} /> |
| 44 | +<button type='submit' {{action 'handleClick'}} /> |
| 45 | +<button {{on 'click' this.handleClick}} /> |
| 46 | +<button {{action 'handleClick'}} /> |
55 | 47 | ``` |
56 | 48 |
|
57 | 49 | ## Related Rules |
|
0 commit comments