Skip to content

Commit b0a94fa

Browse files
authored
Merge pull request #8307 from marmelab/form-validation-mode
[Doc] Document how to change the form validation mode
2 parents 4a44316 + 3aef901 commit b0a94fa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/Validation.md

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ React-admin relies on [react-hook-form](https://react-hook-form.com/) for the va
1414

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

17+
## Validation Mode
18+
19+
By default, the validation mode is `onSubmit`, and the re-validation mode is `onChange`.
20+
21+
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.
22+
23+
```jsx
24+
export const UserCreate = () => (
25+
<Create>
26+
<SimpleForm mode="onBlur" reValidateMode="onBlur">
27+
<TextInput label="First Name" source="firstName" validate={required()} />
28+
</SimpleForm>
29+
</Create>
30+
);
31+
```
32+
1733
## Global Validation
1834

1935
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:

0 commit comments

Comments
 (0)