diff --git a/.gitignore b/.gitignore index 7d0c9448c..1284f2ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea +*iml /node_modules *.log /test/test.js diff --git a/src/js/bootstrap-datetimepicker.js b/src/js/bootstrap-datetimepicker.js index 591bf42a5..6afde347e 100644 --- a/src/js/bootstrap-datetimepicker.js +++ b/src/js/bootstrap-datetimepicker.js @@ -43,6 +43,14 @@ DateTimePicker.prototype = { constructor: DateTimePicker, + getTargetEls: function () { + if (this.options.targetEls.jquery) { + return this.options.targetEls + } else { + return this.$element.find(this.options.targetEls) + } + }, + init: function(element, options) { var icon; if (!(options.pickTime || options.pickDate)) @@ -137,11 +145,11 @@ }, disable: function(){ - this.$element.find('input').prop('disabled',true); + this.getTargetEls().prop('disabled',true); this._detachDatePickerEvents(); }, enable: function(){ - this.$element.find('input').prop('disabled',false); + this.getTargetEls().prop('disabled',false); this._attachDatePickerEvents(); }, @@ -169,7 +177,7 @@ if (!this._unset) formatted = this.formatDate(this._date); if (!this.isInput) { if (this.component){ - var input = this.$element.find('input'); + var input = this.getTargetEls(); input.val(formatted); this._resetMaskPos(input); } @@ -313,7 +321,7 @@ if (this.isInput) { dateStr = this.$element.val(); } else { - dateStr = this.$element.find('input').val(); + dateStr = this.getTargetEls().val(); } if (dateStr) { this._date = this.parseDate(dateStr); @@ -988,14 +996,14 @@ }); } } else { - this.$element.on({ + this.getTargetEls().on({ 'change': $.proxy(this.change, this) - }, 'input'); + }); if (this.options.maskInput) { - this.$element.on({ + this.getTargetEls().on({ 'keydown': $.proxy(this.keydown, this), 'keypress': $.proxy(this.keypress, this) - }, 'input'); + }); } if (this.component){ this.component.on('click', $.proxy(this.show, this)); @@ -1033,11 +1041,11 @@ }); } } else { - this.$element.off({ + this.getTargetEls().off({ 'change': this.change - }, 'input'); + }); if (this.options.maskInput) { - this.$element.off({ + this.getTargetEls().off({ 'keydown': this.keydown, 'keypress': this.keypress }, 'input'); @@ -1095,7 +1103,8 @@ pickSeconds: true, startDate: -Infinity, endDate: Infinity, - collapse: true + collapse: true, + targetEls: 'input' }; $.fn.datetimepicker.Constructor = DateTimePicker; var dpgId = 0;