Just getting started with Yup validation and I'm facing an issue. I am attempting to make certain fields required based on a condition. Specifically, I want the digital object to be required only if hasDigital is true; otherwise, it should be optional. However, no matter what I try, the validation always states that digital.pages is required even when hasDigital is false.
I have attempted to remove the required tag from hasDigital but the problem persists. Any help would be greatly appreciated. Thank you in advance!
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()})
})