Skip to content

Commit 80e384e

Browse files
Sorry for my bad english! I hope you are getting it: I am using datepicker and timepicker as standalone instances on one single page. By using the "altField" the base "_updateAlternate" sets the val() of the altField to the date value of the datepickers, not to the properly val() of the timepickers instances. So i override it and check if the "altFieldTimeOnly" option is set and then put the right formatted time in the altField's val().
1 parent ab8e05f commit 80e384e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,28 @@ $.datepicker._setDateDatepicker = function(target, date) {
11581158
this._setTimeDatepicker(target, tp_date, true);
11591159
};
11601160

1161+
//#######################################################################################
1162+
//override _updateAlternate() to avoid date strings on altFields at initalization if
1163+
//using datepicker and timepicker as standalone on one page
1164+
//#######################################################################################
1165+
$.datepicker._updateAlternate = function(inst) {
1166+
var altField = this._get(inst, 'altField');
1167+
if (altField) { // update alternate field too
1168+
var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
1169+
var date = this._getDate(inst);
1170+
var timeOnly = this._get(inst, 'altFieldTimeOnly');
1171+
if(timeOnly){
1172+
tp_inst = this._get(inst, 'timepicker');
1173+
tp_inst._formatTime();
1174+
var dateStr = tp_inst.formattedTime;
1175+
$(altField).each(function() { $(this).val(dateStr); });
1176+
} else {
1177+
var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
1178+
$(altField).each(function() { $(this).val(dateStr); });
1179+
}
1180+
}
1181+
}
1182+
11611183
//#######################################################################################
11621184
// override getDate() to allow getting time too within Date object
11631185
//#######################################################################################

0 commit comments

Comments
 (0)