Jquery UI Datepicker disabling wrong days

Posted by Nazariy on Stack Overflow See other posts from Stack Overflow or by Nazariy
Published on 2012-10-19T20:12:25Z Indexed on 2012/10/20 11:01 UTC
Read the original article Hit count: 257

Filed under:
|

I have run in to issue that days that have to be disabled are shifted to the next day. The idea is that day that does not exist in our booking object or have a value less than 1 should be disabled on calendar.

here is simplified version of my script and demonstration on jsfiddle:

var bookings = {
    "2012-09-01": 24,
    "2012-09-03": 31,
    "2012-09-05": 27,
    "2012-09-06": 9, 
    "2012-09-07": 18, 
    "2012-09-08": 0, 
    "2012-09-10": 20, 
    "2012-09-12": 19, 
    "2012-09-13": 0, 
    "2012-09-14": 9, 
    "2012-09-15": 24, 
    "2012-09-17": 19, 
    "2012-09-19": 28, 
    "2012-09-20": 15, 
    "2012-09-21": 12, 
    "2012-09-22": 25, 
    "2012-09-24": 19, 
    "2012-09-26": 0, 
    "2012-09-27": 0, 
    "2012-09-28": 0, 
    "2012-09-29": 0
};

function MyEvent(date)
{
    bookings = bookings || {};
    this.date = date.toISOString().substr(0, 10);
    this.display = (typeof bookings[this.date] == 'number' && bookings[this.date] > 0);
    return this;
}

MyEvent.prototype.toArray = function () { 
    return [this.display, null, null]; 
};

$(function ()
{
    $('#eventCalendar').datepicker({
            dateFormat:    "yy-mm-dd",
            firstDay:      1,
            defaultDate:   "2012-09-24",
            beforeShowDay: function (date)
            {
                return new MyEvent(date).toArray();
            }
        }
    );
});

Can some one suggest me what am I doing wrong or is it a bug?

© Stack Overflow or respective owner

Related posts about jquery-ui

Related posts about datepicker