I have a dynamic form using Formik's <Form />
and <FieldArray />
components. I have the validation schema like so:
const countPerKgSchema = total => {
return Yup.object().shape({
rows: Yup.array()
.of(
Yup.object().shape({
count: Yup.string().required('Count is required'),
kg: Yup.string().required('Weight is required.'),
})
)
.required()
.min(1, `Provide at least 1 row`),
saleIds: Yup.array()
.of(Yup.number)
.required(),
});
};
How can I add a validation rule that the sum of all count
s in the rows
array must match total
?