views:

22

answers:

1

I have used the BeforeShowDays method to disable days on page load for my datepicker in the past. What I would like now is to click on a day, and the day should become disabled (not clickable, as if I used the BeforeShowDays method on that day).

Is there a way to accomplish this?

A: 
var disabledDates = [];
    $("#datepicker").datepicker({
        onSelect: function(dateText, inst) { 
            disabledDates.push(dateText);
        },
        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];
     } 

demo here

Reigel