Struggling to figure out this validation schema using Yup for the first time. Essentially, I need to ensure that if hasCategory
is set to true
, at least one category must be selected. Currently, my schema looks like this:
const validationSchema = Yup.object()
.shape({
hasCategory: Yup.boolean().required('Yes or No must be selected for special ad category'),
cat1: Yup.boolean(),
cat2: Yup.boolean(),
cat3: Yup.boolean(),
cat4: Yup.boolean(),
});
Therefore, if hasCategory
is true, then either cat1
, cat2
, cat3
, or cat4
must also be true. However, if hasCategory
is false, none of those categories should be true.
Any help in guiding me towards the right solution would be greatly appreciated!