Question

I'm using the Keith Wood Datepick for a set of dynamically generated set of fromDate and toDate elements.

        var date_defaults = {
        yearRange:'any'

    };

    $("#childList").on("focusin", ".hasDatepicker", function(){
        date_defaults = getChangedDefaultsForToDate(this, "childList", date_defaults);
        $jq(this).datepick(date_defaults);
    });

    function getChangedDefaultsForToDate(elementInFocus, parentDiv, date_defaults){
        if($jq(elementInFocus).hasClass("fromDate")){
            date_defaults.minDate = "";
            currentFromDateElement = $jq(elementInFocus);
        }
        if($jq(elementInFocus).hasClass("toDate")){
            date_defaults.minDate = "";
            defaultToDate = $jq(currentFromDateElement).val();
            alert("new min date: " + defaultToDate);
            date_defaults.minDate = defaultToDate;
        }
        return date_defaults;
    }

The code works fine for the first time. The minDate for the toDate field is restricted based on the selected fromDate. But, when I change the fromDate, the toDate DatePicker still has the old restrictions applied to the calander. The alert towards the end of the code shows me correct/expected values but the calander rendering does not change. Any help would be appreciated.

PS: I could have used a validation plugin but this is built on top of a bunch of existing code and I'm not sure if having a new plugin would increase my worries.

Was it helpful?

Solution

Fixed it by using $(selector).datepick('destroy') before re-rendering the toDate date pop-up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top