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

minDate not working #41

Closed
ThomasAggerholm opened this issue Dec 1, 2020 · 8 comments
Closed

minDate not working #41

ThomasAggerholm opened this issue Dec 1, 2020 · 8 comments

Comments

@ThomasAggerholm
Copy link

Hello,
Thank you for this great library.

I do have a minor issue. The minDate doesn't work. I tried to set it to today's date, but all previous dates remain active.

@ThomasAggerholm
Copy link
Author

Somehow this is working now :-)

@RavenWits
Copy link

I am currently having the same issue how did you managed to work that out?

@ThomasAggerholm
Copy link
Author

I just assigned minDate to new Date() and it worked

@RavenWits
Copy link

I just assigned minDate to new Date() and it worked

Actually I've done the same thing but it still works as maxDate and it disables all the dates beginning from today and all past dates still remains active.

@ThomasAggerholm
Copy link
Author

Hmm this is the code that worked for me:

`
function setDisabledDates() {
const now = new Date()
const unavailableDate = today == 5 ? new Date().addHours(72) : today == 6 ? new Date().addHours(48) : new Date().addHours(24)
let disabledDates = [now, unavailableDate]

    disabledDates = disabledDates.concat(getHolidays(now.getFullYear()));
    disabledDates = disabledDates.concat(getHolidays(now.getFullYear()+1));

    return disabledDates
}

datePickerElement = new Datepicker(dateElem, {
minDate: new Date(),
maxDate: new Date().addHours(24 * 30), // 24 hours times 30 days
autohide: true,
daysOfWeekDisabled: [0, 6],
weekStart: 1,
format: 'dd/mm/yyyy',
language: 'da',
datesDisabled: setDisabledDates()
})`

@RavenWits
Copy link

Thanks for sharing :)

@mousindev
Copy link

Hi,

I am struggling to get the datesDisabled working.

  1. If I try to use your example it will not work as on v1.2.0 it only admits an array of strings (not dates).
  2. If I pass a hardcoded array of string dates like [2022-03-24] it will still not disable the day in the calendar

The only way I managed to have it working was using an example I found inCodeSandbox and modifying it as per the screenshot below
image
When I try that in my project the calendar is not disabling the days marked to be disabled. I tried same code as in the screenshot and also hardcoding dates in all possible formats in case it was related to the locale...

The only difference I see with the live example linked above is that it uses v1.0.2 while I am in v1.2.0

Any hint is more than welcome. Thanks!

@mousindev
Copy link

Hi, just in case someone else faces the same, I finally managed to disable dates using the beforeShowDay instead. I do not have any issues with the format of my dates there. So, every time a day is going to be painted in the calendar, this callback gets executed and there I return the { enabled: isEnabled } based on if the date the cell to be painted represents is one of the dates I have in my string array (with this format as shared in my previous comment: [2022-03-24])of dates to be disabled. It does the trick, but not sure if in terms of performance being able to assign that string array directly to the datesDisabled and have it working would be better.
Cheers!

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

3 participants