Replies: 1 comment 3 replies
-
Conform's zod integration did an additional step to strip empty string for you. You might find it different from the other solutions but this is a very important step to ensure zod pipeline system working as intended: const schema = z.object({
// Let's say you use `min(1)` to ensure the email to be required
email: z.string().min(1, 'Required').email(),
// Does removing `.min(1)` makes it optional?
// No. Zod will continue checking if the email is valid
email: z.string().email(),
}); However if the empty string is stripped, you can do this: const schema = z.object({
// Utlize Zod default require check as empty string will be stripped and become `undefined`
email: z.string({ required_error: 'Required' }).email(),
// Zod will no longer check if the email is valid when email is `undefined`
email: z.string().optional().email(),
}); You can find some tips here on how to customize some of the behaviour. I am not sure about the case with the valibot integration but it is likely because of the same issue. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug and the expected behavior
I want to accept empty strings in my form, but conform sends undefined values instead of empty strings.
Conform version
v1.1.0
Steps to Reproduce the Bug or Issue
Full reproduction: https://stackblitz.com/edit/remix-run-remix-zma3um?file=app%2Froutes%2F_index.tsx
I added the valibot and zod versions.
If you send an empty form, you'll get "The name should be a string" instead of "The name is required".
The description should be valid as an empty string.
I added the optional page that has the expected result but this allows for the field to not be passed, which is not what we want.
What browsers are you seeing the problem on?
Chrome, Firefox, Microsoft Edge, Safari, Others
Screenshots or Videos
No response
Additional context
I originally thought it was related to this issue.
Beta Was this translation helpful? Give feedback.
All reactions