javascriptjquerydatepickermindate

Datepicker minDate stopped working after refactoring for multilingualism


Context: I am currently working on an application that is being refactored so users can choose to display it in one or another language. Everything is going through the "language transition" just fine...except for some small parts.

Problem: The minDate in the javascripts has stopped cooperating after introducing the variable for language. It is supposed to show the current date and is used to make sure that dateEnd can't be a date before the current date/today (=minDate and =dateFrom), but it doesn't work anymore now.

function initDatepickers(){

    $(".datepicker").datepicker({
        dateFormat: "dd-mm-yy",
        //minDate: 0,
    });

    $("#dateFrom").change(function(){
        $("#dateEnd").datepicker('option', 'minDate', $('#dateFrom').val());
    });

    $(".datepicker" ).datepicker("option",$.datepicker.regional[$("#language").val()]);
};

another code snippet from another Javascript file where minDate doesn't work anymore:

    var dateToday = new Date();
$(".datepicker").datepicker({
    dateFormat:'dd-mm-yy',
    beforeShowDay: function(date){
        var day = date.getDay();
        var daysToDisable = [1,2,3,4,5,6];
        for (i = 0; i < daysToDisable.length; i++) {
            if ($.inArray(day, daysToDisable) != -1) {
                return [false];
            }
        }
        return [true];
    },
    minDate: dateToday
});

Can anyone explain why minDate might have stopped working, what am I missing? Thanks in advance! Please let me know if you need any more information, I am pretty new to javascript and I hope I explained my problem clearly enough.


Solution

  • Seems the problem was a piece of code that we didn't use anymore but forgot to delete while refactoring things other than the multilingualism! (the evil-doer was located in the .jsp's, so the problem was not with the javascript code!)

    What happened: the session was hard-coded set to false on the .jsp pages, while it needed to be the default value. In this case it interfered when the language variable was used with the datepicker.

    Everything worked again after deleting the pieces of code which set the session to false.