Skip to content

Commit 610129e

Browse files
author
Alexander Parshin
committed
No errors when call public methods from input without datepicker instance
1 parent 978cc0c commit 610129e

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,19 +1107,23 @@ $.datepicker._gotoToday = function(id) {
11071107
//#######################################################################################
11081108
// Disable & enable the Time in the datetimepicker
11091109
//#######################################################################################
1110-
$.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
1111-
var inst = this._getInst(target),
1112-
tp_inst = this._get(inst, 'timepicker');
1110+
$.datepicker._disableTimepickerDatepicker = function(target) {
1111+
var inst = this._getInst(target);
1112+
if (!inst) return;
1113+
1114+
var tp_inst = this._get(inst, 'timepicker');
11131115
$(target).datepicker('getDate'); // Init selected[Year|Month|Day]
11141116
if (tp_inst) {
11151117
tp_inst._defaults.showTimepicker = false;
11161118
tp_inst._updateDateTime(inst);
11171119
}
11181120
};
11191121

1120-
$.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
1121-
var inst = this._getInst(target),
1122-
tp_inst = this._get(inst, 'timepicker');
1122+
$.datepicker._enableTimepickerDatepicker = function(target) {
1123+
var inst = this._getInst(target)
1124+
if (!inst) return;
1125+
1126+
var tp_inst = this._get(inst, 'timepicker');
11231127
$(target).datepicker('getDate'); // Init selected[Year|Month|Day]
11241128
if (tp_inst) {
11251129
tp_inst._defaults.showTimepicker = true;
@@ -1168,9 +1172,11 @@ $.datepicker._setTime = function(inst, date) {
11681172
// Create new public method to set only time, callable as $().datepicker('setTime', date)
11691173
//#######################################################################################
11701174
$.datepicker._setTimeDatepicker = function(target, date, withDate) {
1171-
var inst = this._getInst(target),
1172-
tp_inst = this._get(inst, 'timepicker');
1173-
1175+
var inst = this._getInst(target);
1176+
if (!inst) return;
1177+
1178+
var tp_inst = this._get(inst, 'timepicker');
1179+
11741180
if (tp_inst) {
11751181
this._setDateFromField(inst);
11761182
var tp_date;
@@ -1193,8 +1199,10 @@ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
11931199
//#######################################################################################
11941200
$.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
11951201
$.datepicker._setDateDatepicker = function(target, date) {
1196-
var inst = this._getInst(target),
1197-
tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
1202+
var inst = this._getInst(target);
1203+
if (!inst) return;
1204+
1205+
var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
11981206

11991207
this._updateDatepicker(inst);
12001208
this._base_setDateDatepicker.apply(this, arguments);
@@ -1206,8 +1214,10 @@ $.datepicker._setDateDatepicker = function(target, date) {
12061214
//#######################################################################################
12071215
$.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
12081216
$.datepicker._getDateDatepicker = function(target, noDefault) {
1209-
var inst = this._getInst(target),
1210-
tp_inst = this._get(inst, 'timepicker');
1217+
var inst = this._getInst(target);
1218+
if (!inst) return;
1219+
1220+
var tp_inst = this._get(inst, 'timepicker');
12111221

12121222
if (tp_inst) {
12131223
this._setDateFromField(inst, noDefault);
@@ -1259,8 +1269,10 @@ $.datepicker._formatDate = function(inst, day, month, year){
12591269
//#######################################################################################
12601270
$.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
12611271
$.datepicker._optionDatepicker = function(target, name, value) {
1262-
var inst = this._getInst(target),
1263-
tp_inst = this._get(inst, 'timepicker');
1272+
var inst = this._getInst(target);
1273+
if (!inst) return null;
1274+
1275+
var tp_inst = this._get(inst, 'timepicker');
12641276
if (tp_inst) {
12651277
var min = null, max = null, onselect = null;
12661278
if (typeof name == 'string') { // if min/max was set with the string

0 commit comments

Comments
 (0)