Form
A form object that contains the core library logic.
Properties
values
values
This is a getter that returns current values
touched
touched
This is a getter that returns current touched. These values are needed when you want to show errors only after the user has touched the field. Usually marked as touched after calling the onBlur
event. The values are flat, see detail.
errors
errors
This is a getter that returns current errors. The values are flat, see detail.
isValid
isValid
Methods
setFieldValue
setFieldValue
Sets a new value, starts validations and notifies all subscribers. For nested values, use name
as described here.
setFieldTouched
setFieldTouched
Marks the field as touched or not and notifies all subscribers. Value by default is true
. For nested values, use name
as described here.
setFieldError
setFieldError
This sets an external error for the field, marks the field as touched, and notifies all subscribers. After changing the field value, this error is reset. For nested values, use name
as described here.
touchAllFields
touchAllFields
Marks all fields with errors as touched and notifies all subscribers. This is useful after trying to submit a form.
reset
reset
Sets the initial values for the values
, touched
, errors
, and notifies all subscribers.
subscribe
subscribe
Adds a subscriber and returns the unsubscribe function.
Please note: the list of subscribers remains unchanged until all subscribers are called. You should keep this in mind when one of the subscribers may initiate the unsubscription of another subscriber.
Last updated