Skip to content

Commit

Permalink
Merge pull request #1732 from thorn0/master
Browse files Browse the repository at this point in the history
Don't trigger `change` when the input value doesn't change
  • Loading branch information
dangrossman authored May 9, 2018
2 parents 6163e1e + 9798f4d commit a244c4d
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

//html template for the picker UI
if (typeof options.template !== 'string' && !(options.template instanceof $))
options.template =
options.template =
'<div class="daterangepicker">' +
'<div class="ranges"></div>' +
'<div class="drp-calendar left">' +
Expand Down Expand Up @@ -336,7 +336,7 @@

// If the end of the range is before the minimum or the start of the range is
// after the maximum, don't display this range option at all.
if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))
if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))
|| (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))
continue;

Expand Down Expand Up @@ -440,13 +440,7 @@
// if attached to a text input, set the initial value
//

if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
this.element.trigger('change');
} else if (this.element.is('input') && this.autoUpdateInput) {
this.element.val(this.startDate.format(this.locale.format));
this.element.trigger('change');
}
this.updateElement();

};

Expand Down Expand Up @@ -1500,12 +1494,14 @@
},

updateElement: function() {
if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
this.element.trigger('change');
} else if (this.element.is('input') && this.autoUpdateInput) {
this.element.val(this.startDate.format(this.locale.format));
this.element.trigger('change');
if (this.element.is('input') && this.autoUpdateInput) {
var newValue = this.startDate.format(this.locale.format);
if (!this.singleDatePicker) {
newValue += this.locale.separator + this.endDate.format(this.locale.format);
}
if (newValue !== this.element.val()) {
this.element.val(newValue).trigger('change');
}
}
},

Expand Down

0 comments on commit a244c4d

Please sign in to comment.