You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Submit this form with a valid email, and with the same email again, to see how it disables the submit button, changes its label, and shows error messages coming from the "backend":
4
+
5
+
```hbs template
6
+
<ToucanForm @onSubmit={{this.handleSubmit}} as |form|>
toucan-form knows about two events that can be asynchronous:
9
+
10
+
-**validation** will often be synchronous, but you can also use the ember-headless-form [asynchronous validations](https://ember-headless-form.pages.dev/docs/validation/custom-validation#asynchronous-validation) for e.g. validating data on the server
11
+
-**submission** is most often asynchronous when e.g. sending a `POST` request with your form data to the server
12
+
13
+
To make the form aware of the asynchronous submission process, you just need to return a Promise from the submit callback passed to [`@onSubmit`](https://ember-headless-form.pages.dev/docs/usage/data#getting-data-out).
14
+
15
+
ember-headless-form will then make the async state of both these events available to you in the template. This allows for use cases like
16
+
17
+
- disabling the submit button while a submission is ongoing
18
+
- showing a loading indicator while submission or validation is pending
19
+
- rendering the results of the (either successful or failed) submission, after it is resolved/rejected
20
+
21
+
To enable these, the form component is yielding `validationState` and `submissionState` objects with these properties:
22
+
23
+
-`isPending`
24
+
-`isResolved`
25
+
-`isRejected`
26
+
-`value` (when resolved)
27
+
-`error` (when rejected)
28
+
29
+
These derived properties are fully reactive and typed, as these are provided by the excellent [ember-async-data](https://github.com/tracked-tools/ember-async-data) addon. Refer to their documentation for additional details!
This demo shows how to implement [yup](https://github.com/jquense/yup) validation with ember-toucan-form, powered by [ember-headless-form](https://ember-headless-form.pages.dev/docs/validation/yup).
9
+
10
+
## Install the adapter package
11
+
12
+
Before using yup validations with Toucan Form, you'll need to install it as a dependency.
0 commit comments