TanStackT
TanStack16mo ago
3 replies
popular-magenta

Form Field Errors From Form Validators using Zod validate all fields

  const form = useForm({
    defaultValues: {
      username: '',
      age: 0,
    },
    validatorAdapter: zodValidator(),
    validators: {
      onChange: z.object({
        username: z.string().min(3, 'Needs to be 3 chars long'),
        age: z.number().min(13, 'You need to be 13'),
      }),
    },
  });


Using this the age field will have an error as soon as an
onChange
-Event has been fired from the
username
field the age field (in fact all fields) are validated and have an error.

Reproduction:
- Go to: https://stackblitz.com/edit/tanstack-form-a6vgcj?file=src%2Findex.tsx
- Type something into the username input
Was this page helpful?