Im building validation scheme and need to make one field required dependent on the value of another field, but validation doesnt work
Heres code example
export const schema = yup.object().shape({
parentField: yup.object().shape({
field1: yup.number(),
field2: yup
.array()
.nullable()
.of(
yup
.object()
.nullable()
.shape({
nestedField1: yup
.string()
.max(64)
.default(null)
.when('parentField.field2.nestedField2', {
is: (val) => val !== null && val !== '',
then: yup.string().required("nestedField2 is required"),
}),
nestedField2: yup
.string()
.nullable()
.default(null)
.when('parentField.field2.nestedField1', {
is: (val) => val !== null && val !== '',
then: yup.string().required("nestedField1 is required"),
}),
})
)
}, [['parentField.field2.nestedField1', 'parentField.field2.nestedField2']]);
Its just doesnt trigger validation and i cant find proper explanation on how to validate nested fields like this in yup