How to represent a boolean as two radio buttons? #301
-
Say you have a couple radio buttons that say "Yes" and "No" and you want these to map back to a boolean in the Zod schema. Would you recommend using the Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
edmundhung
Oct 9, 2023
Replies: 1 comment 3 replies
-
You can use z.string().transform(value => value === 'yes')
// or
z.preprocess(value => value === 'yes', z.boolean()) Note: there seems to be a bug on zod v3.22 (latest version) with regards to |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
halljus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
.preprocess
or.transform
like this:Note: there seems to be a bug on zod v3.22 (latest version) with regards to
.preprocess
, so you might find it not working as expected.