I have used the YUP validation. I need to add validation of startDate and endDate from parent under milestones.
export const validationSchema = Yup.object().shape(
{
name: requiredString,
startDate: Yup.date()
.nullable()
.when('endDate', {
is: (val) => val,
then: Yup.date().nullable().max(Yup.ref('endDate'), 'message'),
}),
endDate: Yup.date()
.nullable()
.when('startDate', {
is: (val) => val,
then: Yup.date().nullable().min(Yup.ref('startDate'), 'message'),
}),
milestones: Yup.array().of(
Yup.object().shape(
{
name: requiredString,
startDate: Yup.date()
.nullable()
.when('endDate', {
is: (val) => val,
then: Yup.date().nullable().max(Yup.ref('endDate'), 'message'),
}),
endDate: Yup.date()
.nullable()
.when('startDate', {
is: (val) => val,
then: Yup.date().nullable().min(Yup.ref('startDate'), 'message'),
}),
},
[['startDate', 'endDate']]
)
),
},
[['startDate', 'endDate']]
);