Skip to content

Commit 496ee3a

Browse files
committed
Bugfix for _onTimeChange to always format time and set timeDefined
1 parent e97d06e commit 496ee3a

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -440,31 +440,31 @@ $.extend(Timepicker.prototype, {
440440
// when a slider moves...
441441
// on time change is also called when the time is updated in the text field
442442
//########################################################################
443-
_onTimeChange: function(force) {
444-
var hour = (this.hour_slider) ? this.hour_slider.slider('value') : this.hour,
445-
minute = (this.minute_slider) ? this.minute_slider.slider('value') : this.minute,
446-
second = (this.second_slider) ? this.second_slider.slider('value') : this.second,
447-
ampm = (hour < 11.5) ? 'AM' : 'PM',
448-
hasChanged = false;
449-
hour = (hour >= 11.5 && hour < 12) ? 12 : hour;
450-
451-
// If the update was done in the input field, this field should not be updated.
443+
_onTimeChange: function() {
444+
var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
445+
minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
446+
second = (this.second_slider) ? this.second_slider.slider('value') : false,
447+
ampm = (hour < 12) ? 'AM' : 'PM';
448+
449+
// If the update was done in the input field, the input field should not be updated.
452450
// If the update was done using the sliders, update the input field.
453-
if (force || this.hour != hour || this.minute != minute || this.second != second || (this.ampm.length > 0 && this.ampm != ampm))
454-
hasChanged = true;
451+
var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm));
452+
453+
if (hasChanged) {
455454

456-
this.hour = parseFloat(hour).toFixed(0);
457-
this.minute = parseFloat(minute).toFixed(0);
458-
this.second = parseFloat(second).toFixed(0);
459-
this.ampm = ampm;
455+
if (hour) {
456+
this.hour = parseFloat(hour).toFixed(0);
457+
this.ampm = ampm;
458+
}
459+
if (minute) this.minute = parseFloat(minute).toFixed(0);
460+
if (second) this.second = parseFloat(second).toFixed(0);
460461

462+
}
461463
this._formatTime();
462464
if (this.$timeObj) this.$timeObj.text(this.formattedTime);
463-
464-
if (hasChanged) {
465-
this._updateDateTime();
466-
this.timeDefined = true;
467-
}
465+
this.timeDefined = true;
466+
467+
if (hasChanged) this._updateDateTime();
468468
},
469469

470470
//########################################################################

0 commit comments

Comments
 (0)