Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

345
Views
Yup validation is not working for nested objects for date keys if we have same name

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']]
);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!