Datetimepicker plugin
I tried a simple test with the following filter, when attempting to getRule, it throws an error that the input is NULL.
$('#builder-widgets').queryBuilder({
plugins: ['bt-tooltip-errors'],
filters: [{
id: 'date',
label: 'datetimepicker',
type: 'datetime',
plugin: 'datetimepicker',
plugin_config: {
}
}]
});
Not sure why the input would return an empty value (https://eonasdan.github.io/bootstrap-datetimepicker/). No error thrown in console.
The problem is that the author of the library decided to not fire the standard "change" event on the input when the datepicker is closed, thus QueryBuilder can't be updated.
You need to manually trigger the "change" event when the date picker is updated (see DP doc about events).
$('#builder-widgets').on('afterCreateRuleInput.queryBuilder', function(e, rule) {
if (rule.filter.id === 'date') {
var $input = rule.$el.find('.rule-value-container [name*=_value_]');
$input.on('dp.change', function() {
$input.trigger('change');
});
}
});
In a next version I'll provide a way to teach QueryBuilder which events to listen to
Yea, I realized after asking the question but your answer is much better!
Thanks for your help and that would be awesome!
good morning
Thank you very much for the contribution, you have done a fantastic job with all your work, congratulations
regards
@davedof happy it helps :-)
@mistic100 is this still relevant or did a new version come out?
A new version of the picker ? I don't know. Yes it's still relevant
@mistic100 no i was referring to your comment "In a next version I'll provide a way to teach QueryBuilder which events to listen to"
Thanks
This feature exists, please read the doc about filters config
+1 This is great answer. I know this is old, but it may help someone else. I tweaked it a little to make it work for any filter that is using the same plugin like this
$('#builder-widgets').on('afterCreateRuleInput.queryBuilder', function (e, rule) {
if (rule.filter.plugin === 'datetimepicker') {
var $input = rule.$el.find('.rule-value-container [name*=_value_]');
$input.on('dp.change', function () {
$input.trigger('change');
});
}
});
But you don't need it anymore, the doc says to use input_event: 'dp.change'
I hope this will also help someone else, but I had default rules that was using the datetimepicker. afterCreateRuleInput doesn't fire on default rules so what I did was initialize the querybuilder and then in another function, added the default rules and used the code @mistic100 provided after the init. THANK YOU!! This helped a lot ^_^