-
Notifications
You must be signed in to change notification settings - Fork 107
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
Handle checkboxes with Zod? #107
Comments
I don't believe so. I borrowed |
Conform does not coerce anything as there is no easy way to determine if the form data was set with a checkbox from the server. You can set it up as |
You can now use |
Sweet! |
How can i validate if at least one checkbox is checked? Any suggestions? |
@luanfonsecap It sounds like you are validating a list of checkboxes. In this case I will define a string array schema with a nonEmpty check. |
But if you only select one checkbox, it becomes a string instead of an array of one value 🤔 |
Yep. It will be a string instead of an array of there is only 1 item. But it should work fine because of the automatic type coercion feature with zod which will transform it to an array before validating it. |
Is there an option to use const schema = z.object({
entries: z.array(z.object({
secret: z.boolean().optional()
})
}) Which does not transform the checkboxes to booleans (even though they have the correct name) - im using it with "transform" right now. Is this a know bug or by design? |
@timzolleis It might be related to #391 if you have no other text inputs inside the object. |
Does conform do anything to coerce a checkbox to a boolean when using a Zod schema?
The text was updated successfully, but these errors were encountered: