Fix bug in setDate, still doesnt set properly before picker is shown

This commit is contained in:
Trent Richardson 2010-10-27 12:53:30 -04:00
parent e5c7cfb697
commit da98d6c3a1

View file

@ -453,9 +453,9 @@
// on time change is also called when the time is updated in the text field // on time change is also called when the time is updated in the text field
//######################################################################## //########################################################################
onTimeChange: function(dp_inst, tp_inst) { onTimeChange: function(dp_inst, tp_inst) {
var hour = tp_inst.hour_slider.slider('value'); var hour = (tp_inst.hour_slider)? tp_inst.hour_slider.slider('value') : tp_inst.hour;
var minute = tp_inst.minute_slider.slider('value'); var minute = (tp_inst.minute_slider)? tp_inst.minute_slider.slider('value') : tp_inst.minute;
var second = tp_inst.second_slider.slider('value'); var second = (tp_inst.second_slider)? tp_inst.second_slider.slider('value') : tp_inst.second;
var ampm = (hour < 11.5) ? 'AM' : 'PM'; var ampm = (hour < 11.5) ? 'AM' : 'PM';
hour = (hour >= 11.5 && hour < 12) ? 12 : hour; hour = (hour >= 11.5 && hour < 12) ? 12 : hour;
var hasChanged = false; var hasChanged = false;
@ -472,6 +472,7 @@
tp_inst.ampm = ampm; tp_inst.ampm = ampm;
tp_inst.formatTime(tp_inst); tp_inst.formatTime(tp_inst);
if(tp_inst.$timeObj)
tp_inst.$timeObj.text(tp_inst.formattedTime); tp_inst.$timeObj.text(tp_inst.formattedTime);
if (hasChanged) { if (hasChanged) {
@ -525,7 +526,7 @@
var formatCfg = $.datepicker._getFormatConfig(dp_inst); var formatCfg = $.datepicker._getFormatConfig(dp_inst);
this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
var formattedDateTime = this.formattedDate; var formattedDateTime = this.formattedDate;
var timeAvailable = dt !== null && tp_inst.timeDefined; var timeAvailable = ((dt !== null && tp_inst.timeDefined) !== true)? false : true;
if(this.defaults.timeOnly === true){ if(this.defaults.timeOnly === true){
formattedDateTime = this.formattedTime; formattedDateTime = this.formattedTime;
@ -541,8 +542,10 @@
} }
this.formattedDateTime = formattedDateTime; this.formattedDateTime = formattedDateTime;
if(!dp_inst.inline && this.$input){
this.$input.val(formattedDateTime); this.$input.val(formattedDateTime);
this.$input.trigger("change"); this.$input.trigger("change");
}
}, },
setDefaults: function(settings) { setDefaults: function(settings) {
@ -633,7 +636,7 @@
timepicker: tp // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); timepicker: tp // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
}); });
return $(this).datepicker(tp.defaults); return input.datepicker(tp.defaults);
}; };
@ -738,7 +741,7 @@
var tp_inst = $.datepicker._get(inst, 'timepicker'); var tp_inst = $.datepicker._get(inst, 'timepicker');
if(tp_inst && tp_inst.hour_slider && tp_inst.minute_slider && tp_inst.second_slider){ if(tp_inst){
var hour = date.getHours(); var hour = date.getHours();
var minute = date.getMinutes(); var minute = date.getMinutes();
var second = date.getSeconds(); var second = date.getSeconds();
@ -750,13 +753,19 @@
second = tp_inst.defaults.secondMin; second = tp_inst.defaults.secondMin;
} }
if(tp_inst.hour_slider && tp_inst.minute_slider && tp_inst.second_slider){
tp_inst.hour_slider.slider('value', hour ); tp_inst.hour_slider.slider('value', hour );
tp_inst.minute_slider.slider('value', minute ); tp_inst.minute_slider.slider('value', minute );
tp_inst.second_slider.slider('value', second ); tp_inst.second_slider.slider('value', second );
}
else{
tp_inst.hour = hour;
tp_inst.minute = minute;
tp_inst.second = second;
}
tp_inst.onTimeChange(inst, tp_inst); tp_inst.onTimeChange(inst, tp_inst);
} }
}; };
//####################################################################################### //#######################################################################################
@ -773,7 +782,6 @@
this._setTime(inst, tp_date); this._setTime(inst, tp_date);
} }
}; };
//####################################################################################### //#######################################################################################
@ -808,3 +816,4 @@
$.timepicker = new Timepicker(true); // singleton instance $.timepicker = new Timepicker(true); // singleton instance
})(jQuery); })(jQuery);