vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.93k stars 239 forks source link

Add support for Zod `.refine` and `.superRefine` #1319

Closed piotrpospiech closed 2 months ago

piotrpospiech commented 3 months ago

This allows to pass to the ZodBridge schema that has refine or superRefine.

Example:

const schema = z
  .object({
    username: z.string().min(4),
    password: z.string().min(8),
    confirmPassword: z.string().min(8),
  })
  .refine((form) => form.password === form.confirmPassword, {
    message: "Passwords don't match",
    path: ["confirmPassword"],
  });
const schema = z
  .object({
    username: z.string().min(4),
    password: z.string().min(8),
    confirmPassword: z.string().min(8),
  })
  .superRefine((val, ctx) => {
    if (val.password !== val.confirmPassword) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: "Passwords don't match",
        path: ["confirmPassword"],
      });
    }
  });
image
codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.56%. Comparing base (4b3f109) to head (4bdd4a0).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1319 +/- ## ======================================= Coverage 94.55% 94.56% ======================================= Files 231 231 Lines 3823 3825 +2 Branches 1030 1031 +1 ======================================= + Hits 3615 3617 +2 Misses 82 82 Partials 126 126 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.