I have a problem requiring the account_id
field when mode_of_payment
has a value.
My code below still doesn’t make the account_id
required when mode_of_payment
has been filled out. mode_of_payment
isn’t a required field but when you fill it out, the account_id
should become required
import { array, boolean, object, string } from 'yup';
const validationSchema = object().shape({
remarks: string().nullable(''),
remittance_items: array().of(
object().shape({
id: string().nullable(),
mode_of_payment_id: object().shape({
id: string().nullable(),
name: string().nullable(),
with_bank_details: boolean(),
}),
account_id: object().shape({
id: string().when('mode_of_payment_id.id', {
is: (id) => !!id,
then: string().required('Select an account'),
otherwise: string().nullable(),
}),
name: string().when('mode_of_payment_id.id', {
is: (id) => !!id,
then: string().required(''),
otherwise: string().nullable(),
}),
}),
})
),
});