Multi step forms with ZOD #6264
-
Hi all, I can only think about creating multiple schemas one for any step in the form and then to manually validate them by the current active step or to manually check if only a subset of elements don't throw an error. Even though it works this way, it's a bit tedious and makes the code bloated. Is there a more elegant solution for this scenario, or am I missing something? Thanks for any help or advice! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
No, there is not any solution besides those that you've mentioned |
Beta Was this translation helpful? Give feedback.
-
There is another idea to try to validate the fields of a specific step using const hasErrors = ['first', 'second'].some((field) => form.validateField(field).hasError);
if (!hasErrors) {
// change the current step
} In this case, you will have one scheme for validation, but during validation, only certain fields will be checked at each step |
Beta Was this translation helpful? Give feedback.
There is another idea to try to validate the fields of a specific step using
form.validateField
In this case, you will have one scheme for validation, but during validation, only certain fields will be checked at each step