Skip to content

How to represent a boolean as two radio buttons? #301

Answered by edmundhung
halljus asked this question in Q&A
Discussion options

You must be logged in to vote

You can use .preprocess or .transform like this:

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 .preprocess, so you might find it not working as expected.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@edmundhung
Comment options

@halljus
Comment options

@edmundhung
Comment options

Answer selected by halljus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants