Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable future and past dates #70

Open
WebMedic-X opened this issue Nov 17, 2020 · 4 comments
Open

Disable future and past dates #70

WebMedic-X opened this issue Nov 17, 2020 · 4 comments

Comments

@WebMedic-X
Copy link

Hi

Currently we can only disable one type of date it seems using isDateDisabled

            isFutureDate(date) {
                const currentDate = new Date();
                return date < currentDate;
            }

We need to disable access to past dates as well limit the selection to not after a certain date

Example:

Do not select past dates from today and only select up to 12/12/2020

Any way to do that?

Thank you

@KuenzelIT
Copy link

You can do this if you wrap vue-date-pick in a custom component and use the isDateDisabled function with two props minDate and maxDate like this:

isDisabled(date)
{
     if (this.isDateDisabled(date))
         return true

     date = moment(date)

     if (this.minDate !== null && date.isBefore(this.minDate))
         return true

     return this.maxDate !== null && date.isAfter(this.maxDate)
 }

At least this is how I solved it.

@rah-emil
Copy link

rah-emil commented Aug 3, 2021

You can do this if you wrap vue-date-pick in a custom component and use the isDateDisabled function with two props minDate and maxDate like this:

isDisabled(date)
{
     if (this.isDateDisabled(date))
         return true

     date = moment(date)

     if (this.minDate !== null && date.isBefore(this.minDate))
         return true

     return this.maxDate !== null && date.isAfter(this.maxDate)
 }

At least this is how I solved it.

This is a stupid and inconvenient solution.

@KuenzelIT
Copy link

It worked for me, but feel free to find another less stupid solution.

@daveokeeffe
Copy link

The isDateDisabled method just returns a boolean, so you can check as many dates as you need to:

<date-pick
  v-model="dateOfBirth"
  class="date-picker"
  :selectable-year-range="{ from: 1900, to: actualYear }"
  :is-date-disabled="isDateOutsideAcceptableRange"
  format="DD-MM-YYYY"
  />
isDateOutsideAcceptableRange(date) {
  const nineteenHundred = new Date('01/01/1900');
  const currentDate = new Date();
  return date < nineteenHundred || date > currentDate;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants