Form status
Get fields and form touched, dirty and submitting statuses
Docs
Package
Touched and dirty state
form.isTouched and form.isDirty fields provide information about the current field status:
- A field is considered to be
touchedwhen the user focused it or its value was changed programmatically with theform.setFieldValuehandler - A field is considered to be
dirtywhen its value was changed and the new value is different from the field value specified ininitialValues(compared with fast-deep-equal)
isTouched and isDirty functions
touchTrigger option
The touchTrigger option allows customizing events that change the touched state.
It accepts two options:
change(default) – the field will be considered touched when its value changes or it has been focusedfocus– the field will be considered touched only when it has been focused
Example of using focus trigger:
Initial values
You can provide initial touched and dirty values with the initialTouched and initialDirty properties.
Both properties support the same field path format as errors:
resetTouched and resetDirty
The form.resetTouched and form.resetDirty functions will make all fields clean and untouched.
Note that form.reset will also reset the touched and dirty state:
To reset the values that are used for the dirty check, call form.resetDirty with new values:
Submitting state
The form.submitting field will be set to true if the function passed to
form.onSubmit returns a promise. After the promise is resolved or rejected,
form.submitting will be set to false:
You can also manually set form.submitting to true or false:
Validating state
The form.validating property is true while any async validation is in
progress. This applies to form.validate(), form.validateField(),
form.isValid(), and the validation triggered by form.onSubmit.
form.isValidating(path) returns true if a specific field is currently being
validated. When form.validate() or form.onSubmit runs all rules, every field
with a rule is considered validating. When form.validateField(path) is called,
only the targeted field is considered validating.