Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always run this.callback if user changed selection #2371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
this.autoUpdateInput = true;
this.alwaysShowCalendars = false;
this.ranges = {};
this.userChangedSelection = false;

this.opens = 'right';
if (this.element.hasClass('pull-right'))
Expand Down Expand Up @@ -1118,6 +1119,7 @@

show: function(e) {
if (this.isShowing) return;
this.userChangedSelection = false;

// Create a click proxy that is private to this instance of datepicker, for unbinding
this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
Expand Down Expand Up @@ -1156,7 +1158,7 @@
}

//if a new date range was selected, invoke the user callback function
if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
if (this.userChangedSelection || !this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel);

//if picker is attached to a text input, update it
Expand Down Expand Up @@ -1212,6 +1214,7 @@
var dates = this.ranges[label];
this.startDate = dates[0];
this.endDate = dates[1];
this.userChangedSelection = true;

if (!this.timePicker) {
this.startDate.startOf('day');
Expand Down Expand Up @@ -1328,6 +1331,7 @@
//special case: clicking the same date for start/end,
//but the time of the end date is before the start date
this.setEndDate(this.startDate.clone());
this.userChangedSelection = true;
} else { // picking end
if (this.timePicker) {
var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
Expand All @@ -1346,13 +1350,15 @@
date = date.clone().hour(hour).minute(minute).second(second);
}
this.setEndDate(date.clone());
this.userChangedSelection = true;
if (this.autoApply) {
this.calculateChosenLabel();
this.clickApply();
}
}

if (this.singleDatePicker) {
this.userChangedSelection = true;
this.setEndDate(this.startDate);
if (!this.timePicker && this.autoApply)
this.clickApply();
Expand Down Expand Up @@ -1452,6 +1458,7 @@
},

timeChanged: function(e) {
this.userChangedSelection = true;

var cal = $(e.target).closest('.drp-calendar'),
isLeft = cal.hasClass('left');
Expand Down Expand Up @@ -1521,7 +1528,7 @@
}

if (!start.isValid() || !end.isValid()) return;

this.userChangedSelection = false
this.setStartDate(start);
this.setEndDate(end);
this.updateView();
Expand Down