Can I add more on an validator onChange besides zod validator?
Currently the docs show this:
but I want to add some other logic such as recording some logic in a store!
But i am not sure how to accomplish that. Anyone has any ideas?
5 Replies
ratty-blush•6mo ago
zod always allows you to manually handle it too
in this case doing
schema.safeParse(value)
and checking if success
is falsestormy-gold•6mo ago
Sounds like a use case for a listener
https://tanstack.com/form/latest/docs/framework/react/guides/listeners
Side effects for event triggers | TanStack Form React Docs
For situations where you want to "affect" or "react" to triggers, there's the listener API. For example, if you, as the developer, want to reset a form field as a result of another field changing, you...
national-goldOP•6mo ago
Luca's answer helped. I didn't go the listener route, because I don't want to place a listener on each field since i have a ton
ratty-blush•6mo ago
if you could turn the zod validator into a reusable function, you can probably do the same with listeners. It's up to you though.
national-goldOP•6mo ago
Yeah totally, appreciate your help!