Uncaught TypeError: Unable to read property '0' from jquery undefined datepicker

advertisements

I have the following jQuery code for datepicker and I'm getting the error Uncaught TypeError: Cannot read property '0' of undefined. I want to do some computations in the beforeShowDay callback but because of this error I'm unable to do so. I'm using jQuery 1.10.2 and jQuery-ui 1.10.4

I found a similar question but none of the solutions seems to be working:

datepicker Error = Uncaught TypeError: Cannot read property '0' of undefined

$(document).ready(function(){
  $("#inline_datepicker").datepicker({
            dateFormat: "yy-mm-dd",
            minDate: 0,
            onSelect: function(){
                fetch_time_slots($(this).datepicker("getDate"));
            },
            beforeShowDay: function(date){
                console.log(date)
            }
    });
});


It looks to be the same problem as your linked question:

You need to return an array from the beforeShowDay callback.

I've updated the fiddle here with this:

$("#inlinedatepicker").datepicker({
        dateFormat: "yy-mm-dd",
        minDate: 0,
        beforeShowDay: function(date){
            console.log(date);
            return [true,""];
        }
});

and it logs all the dates without throwing the Uncaught TypeError.