I have a set of data that i'm tring to validate; It have two fields: "citiesProvided" and "servicesProvided" they are dependent of "LegalCorrespondenceService" that is a array with just one string with the value "true" or "false" Like represented below:
When "true" the validation of the other fields need to be done, otherwise with "false" not. How can i do this conditional validation with yup?
this the code that I had no result:
const schema = Yup.object().shape({
JuridicCorrespondence: Yup.array().of(
Yup.object().shape({
LegalCorrespondenceService: Yup.array()
.of(Yup.boolean())
.length(1, 'Escolha uma opção.'),
citiesProvided: Yup.array().when(['LegalCorrespondenceService'], {
is: 'true',
then: Yup.array()
.of(Yup.string())
.length(1, 'Escolha uma opção.')
}),
servicesProvided: Yup.array().when(['LegalCorrespondenceService'], {
is: 'true',
then: Yup.array()
.of(Yup.string())
.length(1, 'Escolha uma opção.')
}),
})
)
});