diff --git a/docs/framework/angular/guides/validation.md b/docs/framework/angular/guides/validation.md index b50560561..d5b2f44b2 100644 --- a/docs/framework/angular/guides/validation.md +++ b/docs/framework/angular/guides/validation.md @@ -469,6 +469,38 @@ export class AppComponent { } ``` +### Form Level Adapter Validation + +You can also use the adapter at the form level: + +```typescript +import { zodValidator } from '@tanstack/zod-form-adapter' +import { z } from 'zod' + +// ... + +const form = injectForm({ + validatorAdapter: zodValidator(), + validators: { + onChange: z.object({ + age: z.number().gte(13, 'You must be 13 to make an account'), + }), + }, +}) +``` + +If you use the adapter at the form level, it will pass the validation to the fields of the same name. + +This means that: + +```html + + + +``` + +Will still display the error message from the form-level validation. + ## Preventing invalid forms from being submitted The `onChange`, `onBlur` etc... callbacks are also run when the form is submitted and the submission is blocked if the form is invalid. diff --git a/docs/framework/react/guides/validation.md b/docs/framework/react/guides/validation.md index e5bfdc295..0f3a9833d 100644 --- a/docs/framework/react/guides/validation.md +++ b/docs/framework/react/guides/validation.md @@ -477,6 +477,42 @@ These adapters also support async operations using the proper property names: /> ``` +### Form Level Adapter Validation + +You can also use the adapter at the form level: + +```tsx +import { zodValidator } from '@tanstack/zod-form-adapter' +import { z } from 'zod' + +// ... + +const form = useForm({ + validatorAdapter: zodValidator(), + validators: { + onChange: z.object({ + age: z.number().gte(13, 'You must be 13 to make an account'), + }), + }, +}) +``` + +If you use the adapter at the form level, it will pass the validation to the fields of the same name. + +This means that: + +```tsx + + { + return <>{/* ... */} + }} +/> +``` + +Will still display the error message from the form-level validation. + ## Preventing invalid forms from being submitted The `onChange`, `onBlur` etc... callbacks are also run when the form is submitted and the submission is blocked if the form is invalid. diff --git a/docs/framework/solid/guides/validation.md b/docs/framework/solid/guides/validation.md index 354b721bb..50ef40a7a 100644 --- a/docs/framework/solid/guides/validation.md +++ b/docs/framework/solid/guides/validation.md @@ -376,6 +376,44 @@ These adapters also support async operations using the proper property names: /> ``` +### Form Level Adapter Validation + + +You can also use the adapter at the form level: + +```tsx +import { zodValidator } from '@tanstack/zod-form-adapter' +import { z } from 'zod' + +// ... + +const form = createForm(() => ({ + validatorAdapter: zodValidator(), + validators: { + onChange: z.object({ + age: z.number().gte(13, 'You must be 13 to make an account'), + }), + }, +})) +``` + +If you use the adapter at the form level, it will pass the validation to the fields of the same name. + +This means that: + +```tsx + + { + return <>{/* ... */} + }} +/> +``` + +Will still display the error message from the form-level validation. + + ## Preventing invalid forms from being submitted The `onChange`, `onBlur` etc... callbacks are also run when the form is submitted and the submission is blocked if the form is invalid. diff --git a/docs/framework/vue/guides/validation.md b/docs/framework/vue/guides/validation.md index 6819a2d6f..a9aea2c5f 100644 --- a/docs/framework/vue/guides/validation.md +++ b/docs/framework/vue/guides/validation.md @@ -18,20 +18,20 @@ Here is an example: ```vue