Skip to content

form.errors in Conform is empty when returning falsy value from zod string().transform() method #348

Discussion options

You must be logged in to vote

Hi @waldothedeveloper, thanks for preparing a sandbox :)

I notice one problem with the issue path when you are transforming the addons:

const schema = z.object({
  addOn: z.string().transform((val, ctx) => {
    if (val !== "bananas") {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: "The value is not equal to bananas.",
        // The path below make it refers to `addOn.addOn` instead of `addon`, remove it will fix the problem
        path: ["addOn"],
      });
      return null;
    }
    return val;
  }),
});

The problem above is that both zod transform or refine has a concept of base path. As you are transforming at the addOn level, it uses addOn as a base p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@waldothedeveloper
Comment options

Answer selected by waldothedeveloper
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