views:

230

answers:

2

Hey,

I would like to disable certain days like every monday or every tuesday or every monday, thursday friday, etc. on a jQuery UI datepicker.

I tried to play with beforeShowDay, but that requires a specific date. I just want to disable an entire day of the week.

Update: Thanks for the suggested solutions, but they all work for specific dates. What if I wanted to disable every single Monday and Tuesday for the entire year. How would I do that?

A: 
        // April 30,2010 and May 1, 2010 are disabled 
var disabledDates = ['04/30/2010', '05/01/2010']; 

$(function(){ 

    $('#datepicker').datepicker({ 

        dateFormat: 'dd/mm/yy', 
        beforeShowDay: editDays 
    }); 

    function editDays(date) { 
        for (var i = 0; i < disabledDates.length; i++) { 
            if (new Date(disabledDates[i]).toString() == date.toString()) {              
                 return [false]; 
            } 
        } 
        return [true]; 
     }    

}); 
Abu Hamzah
looks familiar... lol
Reigel
+5  A: 

You can ue the beforeShowDate event of the datepicker combined with Date.getDay() to do what you want, like this:

​$("#datepicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 1 && day != 2)];
    }
})​​​​​;​

You can see a working demo here, this just takes the date, checks if it's a Monday (1) or Tuesday (2) and returns false for the first array entry if that's the case.

Nick Craver
Thanks. This works good.
Amir