Skip to content

0.9.4-dev disableTimepicker NaN issue #135

Closed
@AndrewPenry

Description

@AndrewPenry

If you disable a time picker, then change the date, the enable the time picker, the time is NaN:NaN:NaN and everything gets a little broken.

The issue seems to be in _onTimeChange. What happens is this line:

    var hour   = (this.hour_slider) ? this.hour_slider.slider('value') : false,

ends up with hour being an object instead of a number or false.

Add this seems to fix the problem:

    if (typeof(hour) == 'object') hour = false;
    if (typeof(minute) == 'object') minute = false;
    if (typeof(second) == 'object') second = false;
    if (typeof(timezone) == 'object') timezone = false;

_onTimeChange fixed

_onTimeChange: function() {
    var hour   = (this.hour_slider) ? this.hour_slider.slider('value') : false,
        minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
        second = (this.second_slider) ? this.second_slider.slider('value') : false,
        timezone = (this.timezone_select) ? this.timezone_select.val() : false

    if (typeof(hour) == 'object') hour = false;
    if (typeof(minute) == 'object') minute = false;
    if (typeof(second) == 'object') second = false;
    if (typeof(timezone) == 'object') timezone = false;

    if (hour !== false) hour = parseInt(hour,10);
    if (minute !== false) minute = parseInt(minute,10);
    if (second !== false) second = parseInt(second,10);

    var ampm = (hour < 12) ? 'AM' : 'PM';

    // If the update was done in the input field, the input field should not be updated.
    // If the update was done using the sliders, update the input field.
    var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone);

    if (hasChanged) {

        if (hour !== false)this.hour = hour;
        if (minute !== false) this.minute = minute;
        if (second !== false) this.second = second;
        if (timezone !== false) this.timezone = timezone;
        this._limitMinMaxDateTime(this.inst, true);
    }
    if (this._defaults.ampm) this.ampm = ampm;

    this._formatTime();
    if (this.$timeObj) this.$timeObj.text(this.formattedTime);
    this.timeDefined = true;
    if (hasChanged) this._updateDateTime();
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions