I am using yup with formik for managing my form. I use yup for form validation. The problem I am facing is: say I have three fields fieldA, fieldB and fieldC. The validation is: fieldA + fieldB must be equal to fieldC. Here is what I have done using .when but I cannot add a [string, string, string] to the second parameter of yup.object().shape function.
yup.object().shape({
fieldC: yup.number().nullable(),
fieldA: yup.number().nullable()
.when(['fieldA','fieldB', 'fieldC'], {
is: (fieldA, fieldB, fieldC)=> // my condition //,
then: // schemma //,
otherWise: // schemma //,
}),
fieldB: yup.number().nullable()
.when(['fieldA','fieldB', 'fieldC'], {
is: (fieldA, fieldB, fieldC)=> // my condition //,
then: // schemma //,
otherWise: // schemma //,
}),
}, [['fieldA', 'fieldB','fieldC' ]]);