Form actions
Change form state from anywhere in the application
Docs
Package
Usage
Form actions allow you to change the form state from anywhere in your application. The form actions mechanism is similar to the notifications system, modals manager and other similar packages.
To use form actions, set the name property in use-form settings:
Then call the createFormActions function with the same form name as specified in useForm settings:
After that, you can use demoFormActions to change form state from anywhere in your application.
For example, after a fetch request or after a user interaction with a component that does not have access
to the form state:
Form name
Form names must be strings that contain only letters, numbers and dashes:
Note that form names must be unique. If you have multiple forms with the same name, form actions will update the state of all forms with that name.
Form actions
The createFormActions function returns an object with the following methods:
setFieldValuesetValuessetInitialValuessetErrorssetFieldErrorclearFieldErrorclearErrorsresetvalidatevalidateFieldreorderListItemremoveListIteminsertListItemsetDirtysetTouchedresetDirtyresetTouched
All methods work similarly to use-form hook methods – the functions accept the same arguments but do not return anything.