jqueryjquery-uijquery-ui-datepicker

Disable all Sundays and some specific dates in jQuery UI datepicker


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.


Solution

  • It needs to be:

    // date is not a sunday and
    // date is not present in the array
    return [day !== 0 && array.indexOf(string) === -1];
    

    Note that you just need to set the 0th item of the returned array (docs).