Dambo Dambo - 5 months ago 59
jQuery Question

How to make certain months unselectable with datepicker?

I would like to make certain months unselectable. So for example the user should be able to navigate different years, but 'November' will always be greyed-out (or even better, completely excluded from the widget).

Right now, I have tried something like this:

https://jsfiddle.net/4btvnx36/1/

html

<input type="text" id="datepicker" />


js

$(document).ready(function() {
$('#datepicker').datepicker({
beforeShowMonth: function (date) {
if (date.getMonth() == 10) {
return [false];
}
}
});
});

Answer

The jQueryUI datepicker does not have a beforeShowMonth property, only beforeShowDay. You also need to return [true] from that function if the date is valid. With that in mind, try this:

$('#datepicker').datepicker({
    beforeShowDay: function(date) {
        return [date.getMonth() != 10];
    }
});

Updated fiddle