shadcn-vue icon indicating copy to clipboard operation
shadcn-vue copied to clipboard

[Feature]: Add Support for `z.union()` in Validation Schemas

Open zkhan93 opened this issue 1 year ago • 0 comments

Describe the feature

Please add support for z.union() in validation schemas for shadcn Vue. Currently, using z.union() to handle multiple types (e.g., z.string().email() and z.literal('') for optional/nullable fields) is not supported, which limits flexibility.

For example, this schema for an optional email:

email: z.union([z.literal(''), z.string().email().optional()])

renders nothing, likely skipping the field altogether.

Using this:

email: z.string().email().optional()

renders an email field, but when the value is removed, it still shows an invalid email error.

This issue on the Zod repo explains how to define an optional email field using z.union() for proper validation. Screenshot 2024-09-30 at 5 27 09 PM

Additional information

  • [ ] I intend to submit a PR for this feature.
  • [ ] I have already implemented and/or tested this feature.

zkhan93 avatar Sep 30 '24 22:09 zkhan93