Skip to content

Instantly share code, notes, and snippets.

@mattantonelli
Last active July 24, 2020 16:01
Show Gist options
  • Select an option

  • Save mattantonelli/96b9c7b1e30aa1f2cfc6095d0c8201b9 to your computer and use it in GitHub Desktop.

Select an option

Save mattantonelli/96b9c7b1e30aa1f2cfc6095d0c8201b9 to your computer and use it in GitHub Desktop.
JQuery script for initializing a daterangepicker. Replaces "cancel" with a "clear" functionality. Removes default value. https://www.daterangepicker.com/
$(function() {
$('.date-range').daterangepicker({
autoUpdateInput: false,
timePicker: true,
timePickerSeconds: true,
locale: {
cancelLabel: 'Clear',
format: 'YYYY-MM-DD HH:mm:SS'
}
});
$('.date-range').on('apply.daterangepicker', function(_, picker) {
$(this).val(picker.startDate.format(picker.locale.format) + ' - ' + picker.endDate.format(picker.locale.format));
});
$('.date-range').on('cancel.daterangepicker', function(_, _) {
$(this).val('');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment