Skip to content
Source
Sign inSign up
TanStack/form

Bug with zod validation on react form when using both onChange and onBlur form validators #1936

Send to my agent
Closedmaelp(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

I don't have a reproduction because it's too complex to get it from my codebase, but I was getting some weird validation errors, and it turned it it was because I was using all "onBlur", "onChange" and "onSubmit" form validators, and that "onBlur" and "onChange" seems to have "collisions" and got some weird validation errors that would be in inconsistent state all the time

(eg a field that is valid if it is non-empty, I would start typing in it, and it would show as error, until I blur)

it turned out that if I only kept "onChange" and "onSubmit" everything works fine

perhaps something that should be clarified in the docs? or if it's an unwanted bug, to fix it?

Your minimal, reproducible example

n/a

Steps to reproduce

I was using shadcn UI with tanstack form example, and using onBlur + onChange + onSubmit

Expected behavior

It should validate correctly each time I type new characters, but here there were some weird interaction between onBlur and onChange

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

macOs, Chrome, latest versions

TanStack Form adapter

None

TanStack Form version

1.27.3

TypeScript version

No response

Additional context

No response

  1. While we can't fix issues like this without code to try, I'd suggest giving onDynamic a shot if you need more than one validation type:

    https://tanstack.com/form/latest/docs/framework/react/guides/dynamic-validation

Sign in to join this conversation.