Iñaki Guastalli
Iñaki Guastalli

Reputation: 157

jQuery's datepicker "minDate" not working

I'm needing some guidance with a little jQuery's datepicker problem, surely its some detail i'm overseeing.

I'm trying to set some minimum dates for two datepickers; I fetch via ajax a message containing a description, a start date, and an end date, and show those values on a form. For start/end dates, I have jQuery datepickers, and for start date I always set the mininum date as today, which usually overwrites the fetched value. On the other hand, for end date, I want to set the minimum date as whatever is selected on the other datepicker (so you can't cross dates and set an end date lower than start date)

I try to set the EndDate.datepicker minDate as soon as I bind the datepicker, and again after eventually setting a value for StartDate, but it still isn't working on EndDate (it doesn't limit any date, much less update the limit when I change the StartDate)

This's the code I have:

StartDate.datepicker({ minDate: -0 });
EndDate.datepicker({ minDate: StartDate.datepicker("getDate") });

//Initial Behavior - when loading, show last landing message
$.ajax({
    ...
    success: function (data) {


        var fetchedStartDttm = ParseJsonDate(data.GetMessageResult.StartDttm);
        var fetchedEndDttm = ParseJsonDate(data.GetMessageResult.EndDttm);
        var today = new Date();

        if (today <= fetchedEndDttm) {
            //Message still in valid period
            Message.val(data.GetMessageResult.MessageDesc);
            StartDate.datepicker("setDate", fetchedStartDttm);
            EndDate.datepicker("setDate", fetchedEndDttm);
        } else {
            //Last message already expired
            Message.val("Text to be displayed (DELETE THIS REMINDER)");
            StartDate.datepicker("setDate", today);
            EndDate.datepicker("setDate", today);
        }

        //minimum enddate should be at least the startDate
        EndDate.datepicker({ minDate: StartDate.datepicker("getDate") });

    }
});

I'd deeply appreciate any help!

-ccjmk

Upvotes: 0

Views: 5645

Answers (1)

I&#241;aki Guastalli
I&#241;aki Guastalli

Reputation: 157

I found similar questions and they have working solutions (at least for me)

Explaned here:How do I set Min Date in Datepicker from another Datepicker?

and here: Restrict date in jquery datepicker based on another datepicker or textbox

Upvotes: 1

Related Questions