I've three fields : referenceMonth(string), openingDate(string), closingDate(string) in Formik form.
I would add an error to openingDate
when openingDat
isn't the same month as referenceMonth
.
export const VALIDATION_SCHEMA = Yup.object().shape({
'referenceMonth' : Yup.number().required(YUP_DEFAULT_ERROR_VALUE),
'openingDate' : Yup.string().when(['referenceMonth', 'openingDate'], {
is: (referenceMonth: string, openingDate: string) =>
referenceMonth !== `${new Date(openingDate).getMonth()}`,
then: Yup.string().required('Select right month')
}),
})
Terminal says: Error: Cyclic dependency, node was: "openingDate".