I'm new to using Yup validation.
I'm trying to achieve making fields required based on condition.
as u can see below I want to make this digital object required only if hasDigital is true other wise keep it optional, I tried below approach but it always says digital.pages is required , even when I'm passing hasDigital false.
I tried by removing required tag from hasDigital but still facing same issue.
I don't know what am I doing wrong, thanks In advance for any help.
const validationSchema=Yup.object({
hasDigital:Yup.boolean().required(),
digital:Yup.Object({
pages:Yup.number().required(),
price:Yup.number().required()
}).when("hasDigital", {
is:true ,
then: Yup.object().required(),
otherwise:Yup.object().optional()})
})