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

Array of strings values defaults to empty array #60

Closed
SteelAlloy opened this issue Mar 22, 2023 · 5 comments
Closed

Array of strings values defaults to empty array #60

SteelAlloy opened this issue Mar 22, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@SteelAlloy
Copy link

First of all, great lib !

I am trying to group several inputs into an array of values, an array of strings. For the example, the array will be of size 2.

const schema = z.object({
  string_array: z.string().array().nonempty(),
});
    <input type="text" name="string_array" />
    <input type="text" name="string_array" />

image

When submitting the form, I get empty arrays instead of strings.

image
With one of the inputs filled in:
image
image

I may have made a mistake somewhere, and if so please tell me how to do it the right way!

Reproduction repo : https://github.com/oganexon/superform-string-url-array-bug

@ciscoheat
Copy link
Owner

I think that the nonempty modifier may cause some trouble, it may not be fully supported by the zod class parser. Can you try to remove it and see if it works, and if it does, use min instead of nonempty. It should work though, so I will make sure it does for the next release.

@ciscoheat ciscoheat added the bug Something isn't working label Mar 23, 2023
@SteelAlloy
Copy link
Author

SteelAlloy commented Mar 23, 2023

I just removed .noempty(), it does not change anything unfortunately :/

// minimal reproducible example
// bug appears with any primitive type, as long as there's an array
z.number().array()
z.string().array()

@ciscoheat
Copy link
Owner

Yes, confirmed that posting an empty value returns an array! It must have something to do with the type being detected and coerced as an array if empty. Will take care of that straight away.

@ciscoheat
Copy link
Owner

v0.6.3 just released which should fix this. Let me know if things are fine now!

@SteelAlloy
Copy link
Author

Awesome, thanks for the quick fix ! 🎉

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