Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 2 tasks
zkhan93 opened this issue Sep 30, 2024 · 0 comments
Open
1 of 2 tasks

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

zkhan93 opened this issue Sep 30, 2024 · 0 comments

Comments

@zkhan93
Copy link

zkhan93 commented Sep 30, 2024

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant