ShatyUT
ShatyUT

Reputation: 1365

jQuery-Timepicker-Addon removes the time on preloaded dates

I am trying to use the jQuery-Timepicker-Addon by Trent Richardson and have maybe found a bug but figured I'd post here to see if anyone sees something I am doing wrong.

I have a start date/time and end date/time field and am trying to sync them to update minDate/maxDate depending on selections. These two text fields may be populated already when the page loads which appears to be causing me a problem.

Here is a working example of my problem: http://jsfiddle.net/eQmsw/3/

Here is the code inline:

<input id="start" type="text" size="30" value="11/14/2012 02:45 PM" /> <input id="end" type="text" size="30" value="11/28/2012 12:00 AM" />​

$(function() {
    var startDate = new Date(2012,10,14,14,45,0,0);
    var endDate = new Date(2012,10,28,0,0,0,0);
    var startDatePicker = $('#start');
    var endDatePicker = $('#end');
    startDatePicker.datetimepicker({
        defaultDate: startDate,
        maxDate: endDate,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        ampm: true,
        stepMinute: 15,
        timeFormat: 'hh:mm TT',
        onSelect: function(selectedDateTime) {
            var minDate = startDatePicker.datetimepicker('getDate');
            endDatePicker.datetimepicker('option', 'minDate', minDate);
        }
    });
    endDatePicker.datetimepicker({
        defaultDate: endDate,
        minDate: startDate,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        ampm: true,
        stepMinute: 15,
        timeFormat: 'hh:mm TT',
        onSelect: function(selectedDateTime) {
            var maxDate = endDatePicker.datetimepicker('getDate');
            startDatePicker.datetimepicker('option', 'maxDate',  maxDate);
        }
    }); 
});​

If you change one date, the other's time is removed. Once you have changed one date though, and fixed the other with the time removed, all other changes work as expected. I'm setting the 'defaultDate' property of each to a date the corresponds to it's initial value. In real life, I actually parse the date string but thought this would be clearer.

I will also post this in the issues list on the github site for the project but wanted to get this in front of the most people.

Thanks in advance for any help!

Upvotes: 0

Views: 2171

Answers (1)

ShatyUT
ShatyUT

Reputation: 1365

Well, I found something that works. I guess the 'defaultDate' option doesn't work as I was expecting. If it set the date on the datetimepicker after initialization, it works.

startDatePicker.datetimepicker('setDate', startDate);
endDatePicker.datetimepicker('setDate', endDate);

Upvotes: 4

Related Questions