I want to use YUP conditional validation where the value of element answer[0] is used to see if the element ratio[0] is mandatory or not.
I am having trouble accessing the index [0] of answer to do that validation.
Any ideas? (I wrote answer.0 but it did not work).
explosion: Yup.object({
ratio: Yup.object({
0: Yup.number()
.typeError("value between 0 and 1")
.min(0, "Value between 0 and 1")
.max(1, "Value between 0 and 1")
Y.when("answer.0", {
is: "no",
then: (s) => s.notRequired(),
otherwise: (s) => s.required("Explosion probability"),
}),
}),
answer: Yup.object({
0: Yup.string().required("Mandatory field"),
}),
}),