How to create yup validator with array of string type for checkboxes #101
-
I'm using const validator = withYup(
yup.object({
checkboxes: yup.array(yup.string()),
}),
); but when I submit my checkboxes using this validator, I face a weird behavior/bug. If only 1 checkbox is submitted, the Please see this example on stackblitz and github repo Is my |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
A little more digging tells me that there is something wrong in flatten.ts or MultiValueMap.ts which is flattening the one value array |
Beta Was this translation helpful? Give feedback.
-
New issue created |
Beta Was this translation helpful? Give feedback.
-
I responded on the issue, but responding here as well for completeness. Unfortunately, this behavior is a known and documented limitation. To support this use case, you need to write a validator that can handle it being either a single string or an array of strings. I believe there's a way to preprocess values in yup that you could use to do this, but I don't know how that works off the top of my head. |
Beta Was this translation helpful? Give feedback.
I responded on the issue, but responding here as well for completeness. Unfortunately, this behavior is a known and documented limitation. To support this use case, you need to write a validator that can handle it being either a single string or an array of strings. I believe there's a way to preprocess values in yup that you could use to do this, but I don't know how that works off the top of my head.