jQuery datepicker not disabling dates

Im trying to disable dates in the Datepicker, that I retrieve from a array. I used a snippet I found on the internet. When I let the inArray function check the disabledates-array it will return a 0 but it won’t disable the date in the datepicker it self.;

window.disabledSpecificDays = [];
//for loop that will go past some rows in a table and fetch the dates attributes
if(!$.inArray($(this).attr('datumformat'), disabledSpecificDays)){
                disabledSpecificDays.push($(this).attr('datumformat'));
            }    

function disableSpecificDaysAndWeekends(date) {
        var m = date.getMonth();
        var d = date.getDate();
        var y = date.getFullYear();


        for (var i = 0; i < disabledSpecificDays.length; i++) {
            console.log($.inArray(d + '-' + (m + 2) + '-' + y, disabledSpecificDays))
            if ($.inArray(d + '-' + (m + 2) + '-' + y, disabledSpecificDays) != -1 || new Date() > date) {
                return [false];
            }
        }

        var noWeekend = $.datepicker.noWeekends(date);
        return !noWeekend[0] ? noWeekend : [true];
    }

The weekend part of the function works, but I can’t get the dates from the array to be disabled.


Source: jquery

Leave a Reply