longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

Using buttons to disable days #459

Closed RussellJonesPersonal closed 5 years ago

RussellJonesPersonal commented 5 years ago

Hi

I can't figure out how to (or if it's possible to) disable days using an external button or check-boxes?

I need my users to be able to disable any day by clicking Mon - Sun check-boxes (buttons would do fine) placed above the calendar.

Is this possible? Could you advise? Thanks in advance!

Russ

monovertex commented 5 years ago

Hi, please see the beforeShowDay property. This option receives a function that has a date as argument and should return whether the date is selectable or not. It's example 26 from the docs (https://longbill.github.io/jquery-date-range-picker/).

RussellJonesPersonal commented 5 years ago

Thanks for the advice, but this doesn't appear to do what I need it to do. As far as I can tell (forgive me if I'm mistaken) this disables specified dates / days when the calendar is initiated. But it doesn't appear to work if I want to use a button to disable/enable days after init. Am I wrong? Thanks.

monovertex commented 5 years ago

Actually no, that function is executed every time the dropdown is opened, not only when initialized. Please see this JSFiddle.

RussellJonesPersonal commented 5 years ago

Thanks for confirming! I'll have to write something to do this - it's important that the calendar is always open. I appreciate your responses.