I have 2 dropdowns in each row and I can dynamically add and remove rows apart form the first one. I would like to submit form if there is only one row (rendered from the beginning) and it is empty and not be able to submit if:
- value1 is selected without value 2
or
- a new row is added but has no value selected
I am using yup validation.
I have tried with checking the length with .test(), but this test run always after checking 'required'.
This is what I would like to have:
const validationSchema = yup.object({
values:
yup.array()
.of(
yup.object({
value1: yup.string().required(), // ONLY IF ARRAY LENGTH > 1
value2: yup.string().required()// ONLY IF VALUE1 IS SELECTED
})
)});