Skip to content
This repository was archived by the owner on Dec 15, 2017. It is now read-only.

Add targetEls Option that Configures Specific input Elements for Update #201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
*iml
/node_modules
*.log
/test/test.js
Expand Down
33 changes: 21 additions & 12 deletions src/js/bootstrap-datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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();
},

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -1095,7 +1103,8 @@
pickSeconds: true,
startDate: -Infinity,
endDate: Infinity,
collapse: true
collapse: true,
targetEls: 'input'
};
$.fn.datetimepicker.Constructor = DateTimePicker;
var dpgId = 0;
Expand Down