form icon indicating copy to clipboard operation
form copied to clipboard

zodValidator from @tanstack/zod-form-adapter deprecated

Open MahdiiTaheri opened this issue 1 year ago • 4 comments

Describe the bug

zodValidator from zod is deprecated in version 3.24.0 and zod suggests we use standardSchemaValidator instead but there is no such thing in @tanstack/zod-form-adapter in version 0.41.3.

Your minimal, reproducible example

https://stackblitz.com/github/tanstack/form/tree/main/examples/react/zod?embed=1&theme=dark&preset=node&file=src/index.tsx

Steps to reproduce

  1. open index.tsx
  2. you see zodValidator deprecation

Expected behavior

I expected alternative for zodValidator but there is no such thing in @tanstack/zod-form-adapter

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

OS: windows Browser: Google Chrome Version: 132

TanStack Form adapter

react-form

TanStack Form version

0.41.3

TypeScript version

No response

Additional context

No response

MahdiiTaheri avatar Feb 04 '25 05:02 MahdiiTaheri

Since zod 3.24 implemented the Standard Schema interface, you no longer need an adapter to use it on TanStack Form. You can safely remove zodValidator and it will keep working fine as onChange: YourZodSchema :)

Example: https://tanstack.com/form/latest/docs/framework/react/examples/standard-schema

Balastrong avatar Feb 04 '25 08:02 Balastrong

👀

Eigilak avatar Aug 25 '25 16:08 Eigilak

Docs are not up to date with this, see e.g. https://tanstack.com/start/latest/docs/framework/react/guide/middleware#the-inputvalidator-method

frontalicious-martijn avatar Dec 12 '25 13:12 frontalicious-martijn

Upon following the docs the form gets validated as expected.

const form = useForm({
    defaultValues: {
      name: "",
      email: ""
    },
    validators: {
      onSubmit: formSchema,
    },
    onSubmitInvalid: async ({ value }) => {
      toast.error("Please fix the errors in the form before submitting.");
    },
    onSubmit: async ({ value }) => {
      toast.success(
        "Your request has been submitted. We will get back to you soon!",
      );
    },
  });

onSubmit expects type FormValidators but the working code uses zod object to perform validation. This causes my NextJS build to fail. Even VScode highlights this type error. Below is what it is supposed to be but it does not perform validation

validators: {
      onSubmit: formSchema.parse,
    },

I used ts-ignore to skip this type error

pratham-ak2004 avatar Jun 02 '26 16:06 pratham-ak2004