diff --git a/README.md b/README.md index 23ec7376..60909aa0 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ $(document).ready(function() { The constructor also takes an optional options object and callback function. The function will be called whenever the selected date range has been changed by the user, and is passed the start and end dates (moment date objects) -and the range label chosen (if any), as parameters. It will not fire if the picker is closed without any change -to the selected dates. +and the predefined range label chosen (if any), as parameters. It will not fire if the picker is closed without +any change to the selected dates. ```` $('input[name="daterange"]').daterangepicker( @@ -50,7 +50,7 @@ $('input[name="daterange"]').daterangepicker( startDate: '2013-01-01', endDate: '2013-12-31' }, - function(start, end) { + function(start, end, label) { alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); } ); @@ -106,17 +106,28 @@ Several functions are provided for updating the picker's option and state after `setEndDate(Date/moment/string)`: Sets the date range picker's currently selected end date to the provided date +Example usage: + +```` +//create a new date range picker +$('#daterange').daterangepicker({ startDate: '2014-03-05', endDate: '2014-03-06' }); + +//change the selected date range of that picker +$('#daterange').data('daterangepicker').setStartDate('2014-03-01'); +$('#daterange').data('daterangepicker').setEndDate('2014-03-31'); +```` + ## Events Several events are triggered on the element you attach the picker to, which you can listen for: -`show`: Triggered when the picker is shown +`show.daterangepicker`: Triggered when the picker is shown -`hide`: Triggered when the picker is hidden +`hide.daterangepicker`: Triggered when the picker is hidden -`apply`: Triggered when the apply button is clicked +`apply.daterangepicker`: Triggered when the apply button is clicked -`cancel`: Triggered when the cancel button is clicked +`cancel.daterangepicker`: Triggered when the cancel button is clicked Some applications need a "clear" instead of a "cancel" functionality, which can be achieved by changing the button label and watching for the cancel event: @@ -125,7 +136,7 @@ $('#daterange').daterangepicker({ locale: { cancelLabel: 'Clear' } }); -$('#daterange').on('cancel', function(ev, picker) { +$('#daterange').on('cancel.daterangepicker', function(ev, picker) { //do something, like clearing an input $('#daterange').val(''); }); diff --git a/bower.json b/bower.json index cf158ab0..13ccce87 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-daterangepicker", - "version": "1.3.2", + "version": "1.3.3", "main": "daterangepicker.js", "ignore": [ "**/.*", diff --git a/daterangepicker.js b/daterangepicker.js index b504aa96..7b218c1d 100644 --- a/daterangepicker.js +++ b/daterangepicker.js @@ -1,5 +1,5 @@ /** -* @version: 1.3.2 +* @version: 1.3.3 * @author: Dan Grossman http://www.dangrossman.info/ * @date: 2014-01-22 * @copyright: Copyright (c) 2012-2014 Dan Grossman. All rights reserved. @@ -500,7 +500,7 @@ } $(document).on('mousedown', $.proxy(this.hide, this)); - this.element.trigger('show', this); + this.element.trigger('show.daterangepicker', this); }, hide: function (e) { @@ -514,7 +514,7 @@ this.oldEndDate = this.endDate.clone(); $(document).off('mousedown', this.hide); - this.element.trigger('hide', this); + this.element.trigger('hide.daterangepicker', this); }, enterRange: function (e) { @@ -567,7 +567,7 @@ this.container.find('.calendar').hide(); this.hide(); - this.element.trigger('apply', this); + this.element.trigger('apply.daterangepicker', this); } }, @@ -662,7 +662,7 @@ clickApply: function (e) { this.updateInputText(); this.hide(); - this.element.trigger('apply', this); + this.element.trigger('apply.daterangepicker', this); }, clickCancel: function (e) { @@ -672,7 +672,7 @@ this.updateView(); this.updateCalendars(); this.hide(); - this.element.trigger('cancel', this); + this.element.trigger('cancel.daterangepicker', this); }, updateMonthYear: function (e) { diff --git a/examples.html b/examples.html index cfb44176..7cadb6f6 100644 --- a/examples.html +++ b/examples.html @@ -113,9 +113,9 @@

Options Usage