Skip to content

Custom validator function for dynamic forms case #125

Discussion options

You must be logged in to vote

I would lean towards dynamically building a zod schema based on the chosen parameters. If you really want to make a custom validator, you can create an adapter for it.

Have a custom function that takes in the form data, validates it based on the conditions we know, sets the errors on the fields. On every field change, we can call this function and I am not sure how to get the form data or set it using formContext.

To validate on every change, you can customize the validationBehavior of useField.

As for storing form values, this library doesn't store the values at all because we're just submitting the raw form data in the end. You can track field values with useControlField though.

Buil…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by VigneshVaidyanathan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants