T
TanStack2mo ago
extended-salmon

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
No description
No description
No description
No description
4 Replies
rising-crimson
rising-crimson2mo 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-salmon
extended-salmonOP2mo 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
rising-crimson2mo ago
You'll want to get the values like this:
const values = useStore(form.store, (state) => state.values)
const values = useStore(form.store, (state) => state.values)
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-salmon
extended-salmonOP2mo ago
that was what i realised. Thank you pointing out from docs

Did you find this page helpful?