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

Zod union literals with descriptions break the form in form actions #495

Closed
PeytonHanel opened this issue Oct 28, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@PeytonHanel
Copy link

PeytonHanel commented Oct 28, 2024

Description

I have a zod schema with union literals. I put a description on each one and it breaks my superfroms.

export const schema = z.object({
  thingy: z.union([
    z.literal('first').describe('The first one.'),
    z.literal('second').describe('The second one.'),

Once I submit a form to a form action, I will either get an error or the form will receive an empty string instead of the actual selected value. I'm using radio buttons

<input type='radio' bind:group={$form.thingy} value='first' name='thingy'> First
<input type='radio' bind:group={$form.thingy} value='second' name='thingy'> Second

If you remove the name attributes, you get the empty string. If you keep them then you get the error.

image

If applicable, a MRE

I'm not really sure how to use the provided sveltelab link and I had already made a minimal reproducible example here:
https://gitlab.com/peytonhanel/superforms-zod-describe-bug

It will print stuff to the console to help you see what's going on.

@PeytonHanel PeytonHanel added the bug Something isn't working label Oct 28, 2024
@ciscoheat
Copy link
Owner

I see that in the example, you're using use:enhance from SvelteKit, not from superForm. You need to use the Superforms provided one, and one of the events for the validation result, then it will probably work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants