trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

tp_inst.timezone undefined only when using datepicker without timepicker #879

Open wilecoyte78 opened 8 years ago

wilecoyte78 commented 8 years ago

line 1569 has error when only implementing the datepicker like this $( "#fromdate" ).datepicker(); var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);

fixed by adding if statement:

$.datepicker._gotoToday = function (id) {
    var inst = this._getInst($(id)[0]);
    this._base_gotoToday(id);
    var tp_inst = this._get(inst, 'timepicker');
    if (typeof tp_inst != 'undefined')
    {
        var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
        var now = new Date();
        now.setMinutes(now.getMinutes() + now.getTimezoneOffset() + tzoffset);
        this._setTime(inst, now);
        this._setDate(inst, now);
        tp_inst._onSelectHandler();
    }
};
jamescazzetta commented 8 years ago

+1 I am getting the same error, when trying to set date to "Now" I get this error..: Uncaught TypeError: Cannot read property 'timezone' of undefined (jquery.ui.timepicker-addon.js:1569)

..and thus fails to set the date.