Thursday, February 3, 2011

jQuery Datepicker & Date Selection

So I'm trying to set a property on my jQuery datepickers that I found out later is called "defaultDate", when I discovered this thread:


A quick summary: 

These guys are disputing whether or not the date should change in the textbox when you choose a month or year.  Currently, the only way to change the selected date is to click on a date in the calendar part of the datepicker.  Choosing a different month or year will not update the date until you do so.

I found this, that will alter that behaviour (see bold part):

 $("#FromDate").datepicker({
        changeMonth: true,
        changeYear: true,       
        defaultDate: "-40y",
        onChangeMonthYear: function (y, m, i) {
            var d = i.selectedDay + "";
            if (d.length < 2) d = "0" + d;
            var m = m + "";
            if (m.length < 2) m = "0" + m;
            $('#FromDate').val(d + "/" + m + "/" + y);
        }
    });

So the question in the forum that they are debating is: "Should the selected date change when the month and year change?".  To which I will answer an unequivocal, YES!  I don't even think this needs explanation, when you change something, you expect it to change, end of story!

No comments:

Post a Comment