datepicker-change into .clear doesn't work
Opened this issue · 1 comments
Martibis commented
At one point the following code is called:
$("#fromDate").dateRangePicker().bind('datepicker-change', function (event, obj) {
window.clearTimeout($(this).data("timeout"));
$(this).data("timeout", setTimeout(function () {
// Do your thing here
$("#postName").val('');
searchAll();
}, 800));
});
Later I have a button to clear:
$("#clearSearch").click(function () {
$('#fromDate').data('dateRangePicker').clear();
});
The clear will not fire.
If I remove the bind, the clear works perfectly. Any help would be hugely appreciated.
EDIT: To be more complete let me send you the setup of the daterangepicker (may have to do something with always open)
$("#fromDate").dateRangePicker({
inline: true,
container: '#dateRangeDiv',
alwaysOpen: true,
language: 'en',
showShortcuts: true,
customShortcuts: [
{
name: 'week',
dates: function () {
var start = moment(new Date()).toDate();
var end = moment(new Date()).subtract(1, 'weeks').toDate();
return [start, end];
}
},
{
name: 'month',
dates: function () {
var start = moment(new Date()).toDate();
var end = moment(new Date()).subtract(1, 'months').toDate();
return [start, end];
}
},
{
name: 'year',
dates: function () {
var start = moment(new Date()).toDate();
var end = moment(new Date()).subtract(1, 'years').toDate();
return [start, end];
}
},
{
name: 'three years',
dates: function () {
var start = moment(new Date()).toDate();
var end = moment(new Date()).subtract(3, 'years').toDate();
return [start, end];
}
}
],
customTopBar: 'Date range',
monthSelect: true,
yearSelect: true
});
holtkamp commented
As always, a "working" use case helps greatly in understanding the problem and try to figure out what can be improved, for example using: https://jsfiddle.net