Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Document how to change the form validation mode #8307

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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