BTB
BTB

Reputation: 392

Multiple checks in beforeShowDay - jQueryUI datepicker

In short, I want the datepicker to first disable all sundays - I use this code:

jQuery("#datepicker").datepicker({ 
    beforeShowDay: function(day) {
       var day = day.getDay();
       if (day == 0) {
         return [false, "busy"]
       } else {
         return [true, "free"]
       }
     }
});

It works. But then I also want to disable specific dates within a range that is stored in an array:

jQuery("#datepicker").datepicker({ 
    beforeShowDay: function (date) {    
        var dateString = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [dateRange.indexOf(dateString) == -1];
    }
});

This also works and disables the days that I want.

Problem: Both codes works seperately - how can I combine them so both sundays are disabled and my custom dates from the array?

Upvotes: 2

Views: 950

Answers (1)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48407

Hope this will help you. Try following code:

$(function(){  
   $('#thedate').datepicker({
      beforeShowDay: function(date) {
         var dateString = jQuery.datepicker.formatDate('yy-mm-dd', date);
         var day = date.getDay();
         if (day == 0 || dateRange.indexOf(dateString) != -1) {
                return [false, "busy"]
         } else {
                return [true, "free"]
         }
     }
  });   
});

Here is working jsfiddle.

Upvotes: 1

Related Questions