I am trying to disable all Sundays and some specific dates in jQuery UI datepicker. These conditions, together, don’t work in my code. Only sundays are getting disabled. Here is the code
var array = [, '2024-01-07', '2024-01-08', '2024-01-09', '2024-01-10']
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [(day != 0), array.indexOf(string) == -1]
}
});
I want all Sundays and some dates to be disabled in datepicker.
4
Answers
Could you please update this line
with this
See Demo
To disable both all Sundays and specific dates in the jQuery datepicker, you can modify your code as follows:
The key change here is to make sure that you return true for the days you want to enable. In this case, the condition in return checks if the day is not Sunday (day !== 0) and if the date is not in the specified array.
This way, both Sundays and the specific dates in the array will be disabled in the datepicker. The datepicker will only allow the selection of non-Sundays that are not in the specified array.
It needs to be:
Note that you just need to set the 0th item of the returned array (docs).