Form
A form object that contains the core library logic.
Properties
values
values{ [key: string]: any }This is a getter that returns current values
touched
touched{ [path: string]: boolean }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{ [path: string]: string }This is a getter that returns current errors. The values are flat, see detail.
isValid
isValidbooleanMethods
setFieldValue
setFieldValuesetFieldValue(name: string, value: any): voidSets a new value, starts validations and notifies all subscribers. For nested values, use name as described here.
setFieldTouched
setFieldTouchedsetFieldTouched(name: string, isTouched?: boolean): voidMarks the field as touched or not and notifies all subscribers. Value by default is true. For nested values, use name as described here.
setFieldError
setFieldErrorsetFieldError(name: string, message: string): voidThis 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
touchAllFieldstouchAllFields(): voidMarks all fields with errors as touched and notifies all subscribers. This is useful after trying to submit a form.
reset
resetreset(): voidSets the initial values for the values, touched, errors, and notifies all subscribers.
subscribe
subscribeListener(): void
Unsubscribe(): void
subscribe(listener: Listener): UnsubscribeAdds 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
Was this helpful?