Skip to content

Unable to display Zod error for checkbox #596

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

You must be logged in to vote

Conform map each field errors simply by the name. In your case, the name of the favoriteFruits field is favoriteFruit instead of favoriteFruit[0] which result in fields.favoriteFruit.errors being undefined. Similarily, this is why it works properly if you are building a list of fields in which the field names will be favoriteFruit[0], favoriteFruit[1] and so on.

To fix it, please use fields.favoriteFruit.allErrors instead. This gives you an object that includes all errors under favoriteFruit with key being the name of the corresponding errors. If you don't care about the name, you can make it an array like this:

Object.entries(fields.favoriteFruit.allErrors).flatMap(([, messages]) => mess…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by zaru
Comment options

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

@edmundhung
Comment options

@edmundhung
Comment options

@zaru
Comment options

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