Skip to content

Commit 5b95f80

Browse files
committed
update v7.72.0 version
1 parent 0f4594a commit 5b95f80

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/content/docs/useform.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ sidebar: apiLinks
9494
| [criteriaMode](#criteriaMode) | Display all validation errors or one at a time. |
9595
| [shouldFocusError](#shouldFocusError) | Enable or disable built-in focus management. |
9696
| [delayError](#delayError) | Delay error from appearing instantly. |
97+
| [validate](#validate) | Form-level validation is limited to built-in validation methods. |
9798
| [shouldUseNativeValidation](#shouldUseNativeValidation) | Use browser built-in form constraint API. |
9899
| [shouldUnregister](#shouldUnregister) | Enable and disable input unregister after unmount. |
99100
| [disabled](#disabled) | Disable the entire form with all associated inputs. |
@@ -277,6 +278,37 @@ When set to `true` (default), and the user submits a form that fails validation,
277278
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
278279
| This configuration delays the display of error states to the end-user by a specified number of milliseconds. If the user corrects the error input, the error is removed instantly, and the delay is not applied. | <CodeSandbox url="https://codesandbox.io/s/useform-delayerror-q6c2d"/> |
279280

281+
#### validate: <TypeText>Function</TypeText> {#validate}
282+
283+
---
284+
285+
This example demonstrates how to use the **new `validate` API** in combination with `useForm` to perform **form-level validation** in a React application.
286+
287+
The `validate` function receives the entire form object and allows you to return a **structured error** that integrates with `formState.errors`.
288+
289+
**Examples:**
290+
291+
---
292+
293+
```javascript copy
294+
const { register, formState: { errors } } = useForm({
295+
validate: async (formValue) => {
296+
if (formValue.test1.length > formValue.test.length) {
297+
return {
298+
type: 'formError',
299+
message: 'something is wrong here',
300+
};
301+
}
302+
303+
if (formValue.test === 'test') {
304+
return 'direct error message';
305+
}
306+
307+
return true;
308+
},
309+
});
310+
```
311+
280312
#### shouldUnregister: <TypeText>boolean = false</TypeText> {#shouldUnregister}
281313

282314
---

0 commit comments

Comments
 (0)