Skip to content

Commit c31b6a0

Browse files
committed
fix selecting daterange today
! fire selection event if user made a selection, independently of if selection is the same as it was before
1 parent 567ab49 commit c31b6a0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/assets/js/daterangepicker.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
this.autoUpdateInput = true;
5656
this.alwaysShowCalendars = false;
5757
this.ranges = {};
58+
this.userChangedSelection = false;
5859

5960
this.opens = 'right';
6061
if (this.element.hasClass('pull-right'))
@@ -1105,6 +1106,7 @@
11051106

11061107
show: function(e) {
11071108
if (this.isShowing) return;
1109+
this.userChangedSelection = false;
11081110

11091111
// Create a click proxy that is private to this instance of datepicker, for unbinding
11101112
this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
@@ -1143,8 +1145,9 @@
11431145
}
11441146

11451147
//if a new date range was selected, invoke the user callback function
1146-
if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1148+
if (this.userChangedSelection || !this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate)) {
11471149
this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel);
1150+
}
11481151

11491152
//if picker is attached to a text input, update it
11501153
this.updateElement();
@@ -1315,6 +1318,7 @@
13151318
//special case: clicking the same date for start/end,
13161319
//but the time of the end date is before the start date
13171320
this.setEndDate(this.startDate.clone());
1321+
this.userChangedSelection = true;
13181322
} else { // picking end
13191323
if (this.timePicker) {
13201324
var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
@@ -1337,9 +1341,11 @@
13371341
this.calculateChosenLabel();
13381342
this.clickApply();
13391343
}
1344+
this.userChangedSelection = true;
13401345
}
13411346

13421347
if (this.singleDatePicker) {
1348+
this.userChangedSelection = true;
13431349
this.setEndDate(this.startDate);
13441350
if (!this.timePicker)
13451351
this.clickApply();
@@ -1439,6 +1445,7 @@
14391445
},
14401446

14411447
timeChanged: function(e) {
1448+
this.userChangedSelection = true;
14421449

14431450
var cal = $(e.target).closest('.drp-calendar'),
14441451
isLeft = cal.hasClass('left');
@@ -1509,6 +1516,7 @@
15091516

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

1519+
this.userChangedSelection = false
15121520
this.setStartDate(start);
15131521
this.setEndDate(end);
15141522
this.updateView();

0 commit comments

Comments
 (0)