Conditional validation schema
Hello dear community,
I have a problem while validation my form schema (schema.png). I have create and update dialog in the same component (dialog.png). I want to make validation based on dialog mode props (create | update). It makes successful api call (adds or updates the record). However, when i check if form parse is successful or not and it gives me this error(error.png).
I have started this project using create-tsrouter-app configs (tsrouter-config.png).
My question is how to pass dynamic zod validator schema to validators.
Thank you in advance




4 Replies
rising-crimson•2mo ago
L75 is not how you get formFields. What are you trying to do, why are you parsing and console.log'ing the value there?
Also:
z.infer
is the equivalent of z.output
. You'll probably want type Marka
to be z.input
extended-salmonOP•2mo ago
Hi, in L75, i am debugging for the form values whether form is filled correctly or not and to check it passes validation or not
As i mentioned in the description, form submits successfully if i dont add schema.parse(formFields)
I made a stupid mistake by not using
formFields.value
Thank you for the response though @ksgn
rising-crimson•2mo ago
You'll want to get the values like this:
https://tanstack.com/form/latest/docs/framework/react/guides/reactivity#usestore
Reactivity | TanStack Form React Docs
Tanstack Form doesn't cause re-renders when interacting with the form. So you might find yourself trying to use a form or field state value without success. If you would like to access reactive values...
extended-salmonOP•2mo ago
that was what i realised. Thank you pointing out from docs