Skip to content

Commit

Permalink
Merge pull request #8307 from marmelab/form-validation-mode
Browse files Browse the repository at this point in the history
[Doc] Document how to change the form validation mode
  • Loading branch information
fzaninotto authored Oct 26, 2022
2 parents 4a44316 + 3aef901 commit b0a94fa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ React-admin relies on [react-hook-form](https://react-hook-form.com/) for the va

You can’t use both form level validation and input level validation - this is a `react-hook-form` limitation.

## Validation Mode

By default, the validation mode is `onSubmit`, and the re-validation mode is `onChange`.

Since [`<Form>`](./Form.md) actually passes all additional props to react-hook-form's [`useForm` hook](https://react-hook-form.com/api/useform/), this can easily be changed by setting the `mode` and `reValidateMode` props.

```jsx
export const UserCreate = () => (
<Create>
<SimpleForm mode="onBlur" reValidateMode="onBlur">
<TextInput label="First Name" source="firstName" validate={required()} />
</SimpleForm>
</Create>
);
```

## Global Validation

The value of the form `validate` prop must be a function taking the record as input, and returning an object with error messages indexed by field. For instance:
Expand Down

0 comments on commit b0a94fa

Please sign in to comment.