-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hi, first of all, thank you for the amazing work on zod!
I'd like to suggest a feature (or ask if there's a recommended way) to allow refine/check functions to run even when the base schema parsing fails.
Use Case
This would be particularly helpful in the context of form validation, where it's often desirable to run all validation logic and collect all errors in a single pass, even if some fields are already invalid.
Example
const schema = z
.object({
password: z.string().min(8),
confirmPassword: z.string()
})
.refine((data) => data.password === data.confirmPassword, {
message: "Passwords do not match",
path: ["confirmPassword"],
});Currently, if password is too short (e.g. "123"), the refine step doesn't run so we only get the "password too short" error and miss the "passwords do not match" one.
Proposed Behavior
An option that tells zod to run refine/check even when prior parsing failed, so that all relevant errors can be collected and shown to the user.
Would this be feasible or something you'd consider supporting?
Thanks again!