Yup validate is either String or Array of strings
oneOf
only works with literal values. Lazy allows you to provide a schema dynamically as shown below
{
email: yup.lazy(val => (Array.isArray(val) ? yup.array().of(yup.string()) : yup.string()))
}
This YUP simple validation work for my case when Form contains multi-select field and keeping this field as mandatory and at least one option is required to select.
selectOptions: array()
.min(1, "You can't leave this blank.")
.required("You can't leave this blank.")
.nullable()
{
email: yup.mixed()
.when('isArray', {
is: Array.isArray,
then: yup.array().of(yup.string()),
otherwise: yup.string(),
})
}
But a set of checkboxes can produce an array, and text input would not. Are you searching for a solution to validate emails divided by separator?