You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have this kind of form where i can enable some form elements via a checkbox. Of course validation should only kick in when the field is enabled via checkbox. As you can see, the second checkbox just show a text input and the first one a more complex (address) form.
I ve bound my checkbox fields to the apropriate ZOD schema fields called *Boolean. Now i am trying to tell ZOD to only validate when the checkbox aka the *Boolean schema fields are TRUE. For "alternateInvoiceEmail" it works as expected because i dont have any validation on the attribute itself, just in the refinement.
But with alternateInvoiceAddress, i have of course validations because i use this schema in different places. Now what happens is, when i ve never enabled the address field, somehow the validation doesnt kick in and i can submit. When i enabled the address section and enter just one of those fields, which results correctly in an error, i cant disable the validations by just disabling the address section. Errors still remain.
Hope you know what i mean. I am using ZOD with react-hook-form but this doesnt play a big role in my question i assume.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have this kind of form where i can enable some form elements via a checkbox. Of course validation should only kick in when the field is enabled via checkbox. As you can see, the second checkbox just show a text input and the first one a more complex (address) form.
--
This is my ZOD Schema:
I ve bound my checkbox fields to the apropriate ZOD schema fields called *Boolean. Now i am trying to tell ZOD to only validate when the checkbox aka the *Boolean schema fields are TRUE. For "alternateInvoiceEmail" it works as expected because i dont have any validation on the attribute itself, just in the refinement.
But with alternateInvoiceAddress, i have of course validations because i use this schema in different places. Now what happens is, when i ve never enabled the address field, somehow the validation doesnt kick in and i can submit. When i enabled the address section and enter just one of those fields, which results correctly in an error, i cant disable the validations by just disabling the address section. Errors still remain.
Hope you know what i mean. I am using ZOD with react-hook-form but this doesnt play a big role in my question i assume.
Thanks for any help.
Beta Was this translation helpful? Give feedback.
All reactions