yup date validation: datEnd greater than dateStart

Viewed 104

i need to set validation for dateEnd to be greater than dateStart. Now it showing every time when i pick any date even if its greater than startDate. I check lot of solutions but nothing help me resolve this problem. What is wrong in my validation? My validation for this fields:

dateStart: yup.object({
        timestamp: yup
          .date()
          .typeError(t(`forms:validation.dateFormat`))
          .required(t(`forms:validation.isRequired`, { fieldName: t('forms:labels.from') }))
          .max(new Date(), t('forms:validation.dateStartCantBeInFuture')),
      }),
      dateEnd: yup.object({
        timestamp: yup
          .date()
          .required(t(`forms:validation.isRequired`, { fieldName: t('forms:labels.to') }))
          .typeError(t(`forms:validation.dateFormat`))
          .test('toLaterThanTo', t('forms:validation.dateToLaterThanDateFrom'), (value, ctx) => {
            return value ? value >= ctx.parent.dateStart.timestamp : true;
          })
          .nullable(),

0 Answers
Related