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

[Bug] Disabled date inside range #385

Closed
nikeddarn opened this issue Nov 30, 2019 · 9 comments
Closed

[Bug] Disabled date inside range #385

nikeddarn opened this issue Nov 30, 2019 · 9 comments

Comments

@nikeddarn
Copy link

Vue2-datepicker version: 3.1.1
Vue version: 2.6.10
Browser: Chrome Version 78.0.3904.108 (Official Build) (64-bit)

Steps to reproduce
:disabled-date="(date) => date.getDate() === 4;"
Then select range from 2 to 6 for example

Expected behavior
Cant select range that has disabled date or time inside.

Actual behavior
Range selected as usual.

@nikeddarn
Copy link
Author

it will be not hard to set disabled all days after disabled date (time) and before previous disabled date(time) when first date selected . I can't to do that via :disabled-date because i haven't event like "first date selected"

@mengxiong10
Copy link
Owner

mengxiong10 commented Nov 30, 2019

It's a good idea to add the second parameter (the current selected value) to the disabled-date function.

disabledDate(date, currentValue) {
  const firstDate = currentValue[0]
  ...
}

@nikeddarn
Copy link
Author

And to disabledTime(date, currentValue) also

@mengxiong10
Copy link
Owner

mengxiong10 commented Dec 2, 2019

v3.2.0 added it.
disabled-time is not required. Because when you pick a time, the range date is updated. You can use the value of v-model.

@nikeddarn
Copy link
Author

Hi. I wrote code for disabled dates and times using current values with whole usability. It's not optimally without some events like 'CurrentValueChanged' and 'ShowingMonthChanged' but working fine.

Why do you remove passing those parameters to disabled-date and disabled-time in newest version ? I cant upgrade.

@daaner
Copy link

daaner commented Jan 8, 2020

its working good! Thanks!

range
:disabled-date="(date) => date <= disabledBefore"

disabledBefore: this.$moment("31-12-2019", "DD-MM-YYYY"),

@Matvej17
Copy link

Matvej17 commented Dec 2, 2021

Hi guys, I cant apply this issue conversation for solve my problem, but i think, it is same.

For example:
I have set disable days (13.1, 14.1, 15.1) in January
When I picked a range, for example from 10.1 to 20.1 I expected the selection to fail, but no. I can do this selection.

I try work with currentValue but without succes

Can u help me ?

@mengxiong10
Copy link
Owner

mengxiong10 commented Dec 2, 2021

@Matvej17

disabledDate(date, currentValue) {
  const d13 = // new Date(...).getTime()
  const d14 = // ...
  const d15 = // ...
   // when one date is chosen
  if (currentValue.length === 1) {
      const firstDate = currentValue[0]
      if (firstDate.getTime() <  d13) {
         return date.getTime() > d13
      }
  }
  return [d13, d14, d15].indexOf(date.getTime()) !== -1
}

@Matvej17
Copy link

Matvej17 commented Dec 2, 2021

@mengxiong10

Thank you man!! It works

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