From 1f156bff8e20cb762361fbb52fb98769dd29f0d4 Mon Sep 17 00:00:00 2001 From: Mike Robinson Date: Wed, 29 Jun 2016 00:26:29 -0600 Subject: [PATCH 1/3] autoclose() should trigger datepicker-apply When `autoclose` is set to `true`, there is no way to listen to an event where the second date is chosen specifically by the user. If you bind to `datepicker-change` this is also triggered when changing the date programatically using `setDateRange()`, so you can't differentiate between this and being changed by the user. It makes sense to me that `autoclose` should also auto-apply. --- src/jquery.daterangepicker.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/jquery.daterangepicker.js b/src/jquery.daterangepicker.js index 7ee1e4a..17b538d 100755 --- a/src/jquery.daterangepicker.js +++ b/src/jquery.daterangepicker.js @@ -1357,6 +1357,7 @@ showSelectedInfo(); showSelectedDays(); autoclose(); + if (opt.start && opt.end) triggerApply(); } @@ -1386,6 +1387,7 @@ showSelectedInfo(); showSelectedDays(); autoclose(); + triggerApply(); } function isValidTime(time) @@ -1559,6 +1561,26 @@ } } } + + function triggerApply() + { + if (opt.singleDate === true) { + var dateRange = getDateString(new Date(opt.start)); + $(self).trigger('datepicker-apply', + { + 'value': dateRange, + 'date1' : new Date(opt.start) + }); + } else { + var dateRange = getDateString(new Date(opt.start))+ opt.separator +getDateString(new Date(opt.end)); + $(self).trigger('datepicker-apply', + { + 'value': dateRange, + 'date1' : new Date(opt.start), + 'date2' : new Date(opt.end) + }); + } + } function checkSelectionValid() { From 8afb9f01e4fd699adf37f057bfe95aecef828f62 Mon Sep 17 00:00:00 2001 From: Mike Robinson Date: Wed, 29 Jun 2016 12:45:08 -0600 Subject: [PATCH 2/3] Update jquery.daterangepicker.js --- src/jquery.daterangepicker.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/jquery.daterangepicker.js b/src/jquery.daterangepicker.js index 17b538d..a3d4367 100755 --- a/src/jquery.daterangepicker.js +++ b/src/jquery.daterangepicker.js @@ -920,13 +920,7 @@ box.find('.apply-btn').click(function() { closeDatePicker(); - var dateRange = getDateString(new Date(opt.start))+ opt.separator +getDateString(new Date(opt.end)); - $(self).trigger('datepicker-apply', - { - 'value': dateRange, - 'date1' : new Date(opt.start), - 'date2' : new Date(opt.end) - }); + triggerApply(); }); box.find('[custom]').click(function() From 28deac50de9c68ecbe7e86737dc1fbddfb631606 Mon Sep 17 00:00:00 2001 From: Mike Robinson Date: Wed, 29 Jun 2016 13:02:21 -0600 Subject: [PATCH 3/3] Update index.html --- index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 4040f73..cccb79d 100755 --- a/index.html +++ b/index.html @@ -856,7 +856,9 @@

Events

}) .bind('datepicker-apply',function(event,obj) { - /* This event will be triggered when user clicks on the apply button */ + /* This event will be triggered when user clicks on the apply button. + If opt.autoClose is true or opt.showTopbar is false this will also + be triggered when the final date is clicked */ console.log(obj); }) .bind('datepicker-close',function()