Skip to content

Commit 430a960

Browse files
committed
Include chosen range label as 3rd parameter to callback function
Important/useful for if you want to remember the user chose something like 'yesterday' and have it always show the dynamic 'yesterday' on future visits versus a specific date.
1 parent 9b18bcb commit 430a960

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ $(document).ready(function() {
3939
```
4040

4141
The constructor also takes an optional options object and callback function. The function will be called whenever
42-
the selected date range has been changed by the user, and is passed the start and end dates (moment date objects) as
43-
parameters. It will not fire if the picker is closed without any change to the selected dates.
42+
the selected date range has been changed by the user, and is passed the start and end dates (moment date objects)
43+
and the range label chosen (if any), as parameters. It will not fire if the picker is closed without any change
44+
to the selected dates.
4445

4546
````
4647
$('input[name="daterange"]').daterangepicker(

daterangepicker.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335

336336
this.oldStartDate = this.startDate.clone();
337337
this.oldEndDate = this.endDate.clone();
338+
this.oldChosenLabel = this.chosenLabel;
338339

339340
this.leftCalendar = {
340341
month: moment([this.startDate.year(), this.startDate.month(), 1, this.startDate.hour(), this.startDate.minute()]),
@@ -448,7 +449,7 @@
448449

449450
notify: function () {
450451
this.updateView();
451-
this.cb(this.startDate, this.endDate);
452+
this.cb(this.startDate, this.endDate, this.chosenLabel);
452453
},
453454

454455
move: function () {
@@ -514,6 +515,7 @@
514515
},
515516

516517
enterRange: function (e) {
518+
// mouse pointer has entered a range label
517519
var label = e.target.innerHTML;
518520
if (label == this.locale.customRangeLabel) {
519521
this.updateView();
@@ -540,6 +542,7 @@
540542

541543
clickRange: function (e) {
542544
var label = e.target.innerHTML;
545+
this.chosenLabel = label;
543546
if (label == this.locale.customRangeLabel) {
544547
this.showCalendars();
545548
} else {
@@ -661,6 +664,7 @@
661664
clickCancel: function (e) {
662665
this.startDate = this.oldStartDate;
663666
this.endDate = this.oldEndDate;
667+
this.chosenLabel = this.oldChosenLabel;
664668
this.updateView();
665669
this.updateCalendars();
666670
this.hide();

0 commit comments

Comments
 (0)