irimie andrei
irimie andrei

Reputation: 219

How to disable all days from jquery ui calendar EXCEPT the mondays of every week?

I want the user to be able to see all days from within the month, but to be able to select only the mondays of every week. I know that this is done on "beforeshowday" or something like that, but I don't know how. Any help, please ?

Upvotes: 2

Views: 2936

Answers (1)

Fiddle Demo

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

var arr = [1, 2, 3, 4, 5, 6]
$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var day = date.getDay();
        return [(arr.indexOf(day) == -1)];
    }
});


Update Better Use

Fiddle Demo

$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var day = date.getDay();
        return [(day == 0)];
    }
});

Upvotes: 4

Related Questions