question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validate two input dates and max/min ranges

See original GitHub issue

I have two date fields, one for startDate and the other for endDate.

How to validate the startDate not going over the endDate (max value)? And the opposite as well, the endDate not going farther than the startDate (min value).

I tried doing the following but resulted in a cyclic dependency

startDate: yup
      .date()
      .when(
        'endDate',
        (endDate, schema) => (endDate && schema.max(endDate)),
      ),
endDate: yup
      .date()
      .when(
        'startDate',
        (startDate, schema) => (startDate && schema.min(startDate)),
      ),

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

47reactions
davidtatisNativeAppscommented, Jun 12, 2019

What about


startDate: yup
      .date()
      .required(),
endDate: yup
      .date()
      .when(
        'startDate',
        (startDate, schema) => (startDate && schema.min(startDate)),
      ),
15reactions
Randorecommented, Sep 28, 2018

I am also facing a similar issue, why someone has not posted an answered to this problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advice on how to compare a date input value against min ...
I see you are already using moment . You can parse the date strings using moment and get a native date object from...
Read more >
Min / Max Date Validation and Compare Validation for Two ...
In some cases you want to have the end users select dates within given ranges and to ensure one date is before the...
Read more >
Dynamically set the max min date at input field with React
In this article, I will show you a very simple example to demonstrate the situation that if you writing a admin to limit...
Read more >
Lookup min max values within a date range
This article explains how to find the smallest and largest value using two conditions. In this case they are date conditions but they...
Read more >
creating a date range with two input type date widgets
<form action="#" class="ws-validate">. 2. <div class="form-row">. 3. <!-- max of the first date equals value of the second --> <!-- mmin of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found