currentPrescriptionMedsQuestion: yup.string().required('Required'), //----- need context value
currentNonPrescriptionMedsQuestion: yup.string().required('Required'),
currentPrescriptionMeds: yup.array(yup.object({
name: yup.string().when('currentPrescriptionMedsQuestion', {
is: (val: string) => val === 'Yes', //----- val is undefined
then: yup.string().required('Required'),
otherwise: yup.string().notRequired()
}).default(''),
frequency: yup.string().when('currentPrescriptionMedsQuestion', {
is: (val: string) => val === 'Yes',
then: yup.string().required('Required'),
otherwise: yup.string().notRequired()
}).default(''),
otherFrequency: yup.string().when('frequency', {
is: (val: string) => val === 'Other',
then: yup.string().default('').required('Required'),
otherwise: yup.string().notRequired()
}).default(''),
dose: yup.string().when('currentPrescriptionMedsQuestion', {
is: (val: string) => val === 'Yes',
then: yup.string().default('').required('Required'),
otherwise: yup.string().notRequired()
}).default('')
})),
I'm trying to get the value I need, but when I try to log it and bind to it, I get undefined How to get a specific val inside an array with an object?