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

[Feature request] Min/Max date ranges that disable arrows, hide invalid months/years. #628

Open
Billiam opened this issue Jul 20, 2021 · 12 comments
Labels

Comments

@Billiam
Copy link

Billiam commented Jul 20, 2021

The disabledDate API works great for discrete ranges of date, but it would be nice to be able to disable dates in such a way that next/previous arrows are also disabled, and to hide invalid months or years in the date picker that fall outside of the range.

For example: When entering birthdate, dates in the future may not be needed. When scheduling an appointment, dates in the past may not be needed.

Ideally, setting a maxDate to new Date() would:

  • Disable the rest of days in the current month
  • Disable the next / double next arrows
  • Hide future months in the month picker
  • Hide future years in the year picker
@urbgimtam
Copy link

urbgimtam commented Jul 28, 2021

Agree. The ability to disable or hide both future and past invalid dates would be a great addition.

This is related to #380 ([Bug] When disabled-date is specified, we can still select Year and Month)

@ikasianiuk
Copy link

any plans to implement this? it would be really nice to have this feature

@AlexanderSevruk
Copy link

Hey, Any updates on this one?

@mengxiong10
Copy link
Owner

PR welcome!

@Pranavraut033
Copy link

Pranavraut033 commented Dec 17, 2021

@mengxiong10 Hey I have created a PR for this issue.

@svenjahn
Copy link

Hey, are there any news on the PR?

@agnieszkabugla
Copy link

@mengxiong10 , will the PR be merged any time soon? i would love to use this feature ;)

@mengxiong10
Copy link
Owner

@agnieszkabugla I'll add it in next week

@mengxiong10
Copy link
Owner

I add disabledCalendarChanger in v3.11.0

Simple 🔽

<template>
   <date-picker :disabled-date="disabledDate" :disabled-calendar-changer="disabledDate" />
</template>

<script>
export default {
  methods: {
    disabledDate(date) {
      const today = new Date().setHours(0, 0, 0, 0)
      return date < new Date(today);
    },
  },
};
</script>

Advance🔽

<template>
   <date-picker :disabled-date="disabledDate" :disabled-calendar-changer="disabledCalendarChanger" />
</template>

<script>
export default {
  methods: {
    disabledDate(date) {
      const today = new Date().setHours(0, 0, 0, 0)
      return date < new Date(today);
    },
    disabledCalendarChanger(date, type) {
       // type: last-year , last-month, next-year, next-month, last-decade, next-decade, year, month
       if (type === 'year' || type === 'month') {
           return false
        }
       return this.disabledDate(date)
    }
  },
};
</script>

@tomastan
Copy link

tomastan commented Nov 10, 2022

This feature is good, but we found some quirks with the result. If dates are disabled in future, but the current value is long time in the past (in my example 2020-10-01) arrows do not work in neither direction and all dates in current month are disabled as well.

image

I found two ways to resolve it finall:

  1. to clear the date first
  2. click on the year and select it in the future. Hence it still confusing since I cannot select the current year (2023 is the closest option for some reason)

I made a fiddle to explain it:
https://jsfiddle.net/m17qnayv/1

While it may be logical, but a bit confusing for regular users and even for me ;). So maybe it could be possible to let the selector arrows work, but fast-forward to the closest suitable period?

@parsajiravand
Copy link

@mengxiong10
thanks bro , you save my day

@truesteps
Copy link

Any updates on this issue :)?

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

No branches or pull requests