Skip to content

[BUG] - <UForm /> Zod custom error object parses incorrectly, using multiple paths #3894

Open
@saltytostitos

Description

@saltytostitos

Environment

  • Operating System: Darwin
  • Node Version: v22.14.0
  • Nuxt Version: 3.16.2
  • CLI Version: 3.24.1
  • Nitro Version: 2.11.9
  • Package Manager: [email protected]
  • Builder: -
  • User Config: compatibilityDate, devtools, modules, future, app, experimental, css, devServer, icon, vite, $development
  • Runtime Modules: @nuxt/[email protected], @nuxt/[email protected], @nuxt/[email protected]
  • Build Modules: -

Uzing UI3 Pro v3.0.2

Is this bug related to Nuxt or Vue?

Nuxt

Version

3.0.2

Reproduction

https://codesandbox.io/p/devbox/strange-frost-mv7k2c

Description

Using Zod on <UForm>
When using z.refine() and passing a path parameter, the path is parsed incorrectly.
Possibly from: form.ts#45

Example Schema:

const schema = z
  .object({
    email: z
      .union([
        z.string().email(),
        z.literal(""),
      ])
    phone: z
      .union([
        z.string(),
        z.literal(""),
      ])
  })
  .refine(({ phone, email }) => phone?.length || email?.length, {
    message: "Please provide either an email or a phone number",
    path: ["phone", "email"],
  });

The resulting error from the From element shows name as "phone.email":

  {
    _custom: {
      type: "reactive",
      stateTypeName: "Reactive",
      value: {
        name: "phone.email",
        id: "__vue_devtool_undefined__",
      },
    },
  },
];

The zod error result is: ["phone", "email"]

{
  code: "custom",
  path: ["phone", "email"],
};

Workaround:
I can pass one path at a time, by using ["phone"] but I cannot pass multiple paths.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagev3#1289

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions