Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow refine to run even if base schema parsing fails #4598

Copy link
Copy link
@marcomuser

Description

@marcomuser
Issue body actions

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.