Given the following Yup schema:
const myValSchema = Yup.object().shape({
myGroups: Yup.array()
.of(
Yup.object().shape({
myName: Yup.string()
.required('Name is required')
mySelection: Yup.number().required('Selection is required'),
myHobbies: Yup.array().of(
Yup.object().shape({
hobbyName: Yup.string()
.required('Hobby name is required'),
hobbyLikes: Yup.number()
.nullable()
.when("dummy", {
is: (value) =>
mySelection === 99,
then: Yup.number().typeError('Value must be a number').required('Likes is required').positive(),
}),
})
)
})
)
});
I need to validate hobbyLikes only when the value of mySelection outside of this shape equals 99 but I am unsure how to access this outside value.
Just unsure how to achieve this.