Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

shared-code.ts

27 lines491 Bytes

1import { formOptions } from '@tanstack/react-form'
2import { z } from 'zod'
3​
4const clientSchema = z.object({
5 age: z.number().min(8),
6})
7​
8export const serverSchema = z.object({
9 age: z.number().min(12),
10})
11​
12export const formOpts = formOptions.strictSchema(clientSchema, {
13 defaultValues: {
14 age: 0,
15 },
16 validators: [
17 {
18 triggers: ['change'],
19 run: clientSchema,
20 },
21 {
22 triggers: ['server'],
23 runOnSubmit: false,
24 run: serverSchema,
25 },
26 ],
27})