form.errors is an object with one message per field. Its keys are the field paths, such as email or user.email.
A field without an error has no key.
Validation in the browser cannot know everything. When the server rejects a value, call setFieldError or setErrors with the message.
The field shows it right away, and it clears when the user changes that field.
The server rejects this email, so the field shows its message.
clearFieldError(path) removes one error and clearErrors() removes all of them.
Changing a field also clears its error, unless validateInputOnChange is on for it.
onSubmit takes a second handler that runs when validation fails. It receives the errors and the values.
<form onSubmit={form.onSubmit(save, (errors) => console.log(errors))}>
| Name | Description | Type |
|---|---|---|
| errors | one message per field path | Record<string, string> |
| setErrors | replace all errors | (errors: Record<string, string>) => void |
| setFieldError | set the error of one field | (path: string, message: string) => void |
| clearErrors | remove all errors | () => void |
| clearFieldError | remove the error of one field | (path: string) => void |