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

Select other dates even there are disabled date in the middle of desired dates #449

Closed windchime18 closed 5 years ago

windchime18 commented 5 years ago

Is it possible to select dates between a disabled date? I tried to disable a specific date. e.g. (2018-08-17). I still want to select dates from 2018-08-16 to 2018-08-18.

function pad(number, length) {

                var str = '' + number;
                while (str.length < length) {
                    str = '0' + str;
                }

                return str;

            }
beforeShowDay: function(t)
                {
                    $dates = '2018-08-17';
                    $calendar_date = t.getFullYear()+"-"+(pad(t.getMonth()+1, 2))+"-"+pad(t.getDate(), 2);
                    var valid = !($calendar_date == $dates);
                    var _class = valid ? '' : 'invalid';
                    var _tooltip = valid ? '' : 'This is already taken.';
                    return [valid,_class,_tooltip];
                },
holtkamp commented 5 years ago

mm, it seems this is possible, have a look at https://github.com/longbill/jquery-date-range-picker/issues/352

closing for now

windchime18 commented 5 years ago

Hello Sir, it seems that the solution doesn't match with my problem. Please check the link containing my sample image for date select.

date range

You can see there that the red shaded date has an "invalid" class. This cannot be selected. but i still wanted to select the next day.

Disabled date: August 17, 2018.

Desired date range to select: August 15 to 18, 2018.

holtkamp commented 5 years ago

@windchime18 thanks for the screenshot, that helps understanding your case! Indeed, I think by default this is not supported.

When looking at example#26 at https://longbill.github.io/jquery-date-range-picker/ this does also not work by default.

But it seems it is possible, please see this comment https://github.com/longbill/jquery-date-range-picker/issues/352#issuecomment-351705025, it refers to this example: https://jsfiddle.net/maximelafarie/dnbd01do/21/

In that example the Sundays are disabled, but I can easily select a range from Friday to Monday...

Does this help you?

windchime18 commented 5 years ago

Thanks a lot. this worked for me

holtkamp commented 5 years ago

Credits go to @maximelafarie !

Maybe this functionality can be adopted in the library, a Pull Request would be welcome.