JQuery Datepicker combine multiple functions in beforeShowDay

Viewed 208

I'm hoping there's a simple solution to my question. I'm trying to disable weekends and a few select days in JQuery datepicker. I figured out how to disable certain dates but can't figure out how to add the "noWeekends" command. Can someone help me?

Here is the code:

var holidays = ["12/24/2020","12/25/2020", "12/31/2020"];
$(document).ready(function(){
 $("#datepicker").datepicker({ 
        beforeShowDay: function(date){
            var string = jQuery.datepicker.formatDate('mm/dd/yy', date);
            return [ holidays.indexOf(string) == -1 ]
        },
        beforeShowDay: $.datepicker.noWeekends // THIS IS NOT WORKING
    });
});

I'm just trying to combine the noWeekend command along with my holidays. Thank you!!

1 Answers

Ok, I figured it out by looking at the JQuery code and seeing how they used noWeekends. Here is the solution:

var holidays = ["12/24/2020","12/25/2020", "12/31/2020"];
...
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('mm/dd/yy', date);
var day = date.getDay();
return [ ( day > 0 && day < 6 && holidays.indexOf(string) == -1), "" ];
Related