Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sunday only on Jquery Datepicker?

AIM: TO only allow users to select sunday on the datpicker calendar.

Currently I have it almost done, except for some reason every other day except Sunday works. When I use 7 for Sunday in the code below the entire calendar is unclickable, any other day works perfect.

$(document).ready(function() {

    $("#datepicker2").datepicker({ 
        autoSize: true,         // automatically resize the input field 
        altFormat: 'yy-mm-dd',  // Date Format used
        firstDay: 1, // Start with Monday
        beforeShowDay: function(date)

        { return [date.getDay() == 7,''];}}); // Allow only one day a week
});

Question: How can I only allow Sunday selection?

like image 667
Rhys Avatar asked Feb 15 '13 17:02

Rhys


1 Answers

Date.getDay() returns a value in the range 0-6, not 1-7.

beforeShowDay: function(date) {
    return [date.getDay() === 0,''];
}
like image 147
Matt Ball Avatar answered Sep 28 '22 01:09

Matt Ball