Skip to content

Commit cba6c34

Browse files
authored
Merge pull request #197 from CrowdStrike/yield-reset-and-submit
Yield reset and submit actions
2 parents 1619307 + bf5aca5 commit cba6c34

File tree

8 files changed

+231
-9
lines changed

8 files changed

+231
-9
lines changed

.changeset/empty-carrots-laugh.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@crowdstrike/ember-toucan-form': patch
3+
---
4+
5+
The `ToucanForm` component now yields back `submit` and `reset` actions as the functionality was added to `ember-headless-form` [in this PR](https://github.com/CrowdStrike/ember-headless-form/pull/136).
6+
7+
**NOTE:** Calling `submit` directly is **not** required for most cases. The implementation only requires a button tag with the `type="submit"` attribute set.
8+
9+
```hbs
10+
<ToucanForm as |form|>
11+
{{! This should be used for most cases }}
12+
<button type='submit'>Submit</button>
13+
<button {{on 'click' form.reset}} type='button'>Reset</button>
14+
</ToucanForm>
15+
```
16+
17+
However, if you have a more complex case with submission, you can use `form.submit`.
18+
19+
```hbs
20+
<ToucanForm as |form|>
21+
<button {{on 'click' form.submit}} type='button'>Submit</button>
22+
<button {{on 'click' form.reset}} type='button'>Reset</button>
23+
</ToucanForm>
24+
```

docs/toucan-form/changeset-validation/index.md

+23
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,26 @@ const data: MyFormData = {};
5151
<form.Input @label='Last name' @name='lastName' />
5252
</ToucanForm>
5353
```
54+
55+
## Submit and Reset Actions
56+
57+
The component yields back `submit` and `reset` actions for more complex cases of submitting or resetting your form data.
58+
59+
**NOTE:** Calling `submit` directly is **not** required for most cases. The implementation only requires a button tag with the `type="submit"` attribute set.
60+
61+
```hbs
62+
<ToucanForm as |form|>
63+
{{! This should be used for most cases }}
64+
<button type='submit'>Submit</button>
65+
<button {{on 'click' form.reset}} type='button'>Reset</button>
66+
</ToucanForm>
67+
```
68+
69+
However, if you have a more complex case with submission, you can use `form.submit`.
70+
71+
```hbs
72+
<ToucanForm as |form|>
73+
<button {{on 'click' form.submit}} type='button'>Submit</button>
74+
<button {{on 'click' form.reset}} type='button'>Reset</button>
75+
</ToucanForm>
76+
```

docs/toucan-form/native-validation/index.md

+23
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,26 @@ const data: MyFormData = {};
3434
<form.Input @label='Last name' @name='lastName' />
3535
</ToucanForm>
3636
```
37+
38+
## Submit and Reset Actions
39+
40+
The component yields back `submit` and `reset` actions for more complex cases of submitting or resetting your form data.
41+
42+
**NOTE:** Calling `submit` directly is **not** required for most cases. The implementation only requires a button tag with the `type="submit"` attribute set.
43+
44+
```hbs
45+
<ToucanForm as |form|>
46+
{{! This should be used for most cases }}
47+
<button type='submit'>Submit</button>
48+
<button {{on 'click' form.reset}} type='button'>Reset</button>
49+
</ToucanForm>
50+
```
51+
52+
However, if you have a more complex case with submission, you can use `form.submit`.
53+
54+
```hbs
55+
<ToucanForm as |form|>
56+
<button {{on 'click' form.submit}} type='button'>Submit</button>
57+
<button {{on 'click' form.reset}} type='button'>Reset</button>
58+
</ToucanForm>
59+
```

packages/ember-toucan-form/src/components/toucan-form.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
Textarea=(component
3131
(ensure-safe-component this.TextareaFieldComponent) form=form
3232
)
33+
reset=form.reset
34+
submit=form.submit
3335
)
3436
}}
3537
</HeadlessForm>

packages/ember-toucan-form/src/components/toucan-form.ts

+16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ export interface ToucanFormComponentSignature<
3838
'form'
3939
>;
4040
Textarea: WithBoundArgs<typeof TextareaFieldComponent<DATA>, 'form'>;
41+
42+
/**
43+
* Yielded action that will trigger form validation and submission, same as when triggering the native `submit` event on the form.
44+
*
45+
* View ember-headless-form's documentation for more information.
46+
*
47+
* Note that calling this directly is **not** required for most cases. The implementation only requires a button tag with the `type="submit"` attribute set; however, this is exposed for more complex cases.
48+
*/
49+
submit: () => void;
50+
51+
/**
52+
* Yielded action that will reset form state, same as when triggering the native `reset` event on the form.
53+
*
54+
* View ember-headless-form's documentation for more information.
55+
*/
56+
reset: () => void;
4157
}
4258
];
4359
};

pnpm-lock.yaml

+67-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/ember__destroyable": "^4.0.1",
5757
"@types/ember__engine": "^4.0.4",
5858
"@types/ember__error": "^4.0.2",
59+
"@types/ember__modifier": "^4.0.3",
5960
"@types/ember__object": "^4.0.5",
6061
"@types/ember__polyfills": "^4.0.1",
6162
"@types/ember__routing": "^4.0.12",
@@ -89,8 +90,8 @@
8990
"ember-load-initializers": "^2.1.2",
9091
"ember-qunit": "^7.0.0",
9192
"ember-resolver": "^10.0.0",
92-
"ember-source-channel-url": "^3.0.0",
9393
"ember-source": "~5.1.0",
94+
"ember-source-channel-url": "^3.0.0",
9495
"ember-template-imports": "^3.1.2",
9596
"ember-template-lint": "^5.8.0",
9697
"ember-try": "^2.0.0",

0 commit comments

Comments
 (0)