I have the following object:
const values = {
people: [
{
name: "Mark",
age: null
},
{
name: "Shark",
age: 31
}
],
isAgeRequired: false
};
When isAgeRequired flips to true, in my Yup schema I would like to make the age value for each object in the people array require.
I have the following yup schema definition, but right now it seems to validate successfully even if the above requirements are not met:
const validator = object({
people: array(
object({
name: string().required(),
age: number()
.nullable()
.when("isAgeRequired", {
is: true,
then: (schema) => schema.required()
})
})
)
});