jQuery-QueryBuilder icon indicating copy to clipboard operation
jQuery-QueryBuilder copied to clipboard

Datetimepicker plugin

Open angelinacc opened this issue 11 years ago • 11 comments

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.

angelinacc avatar Oct 08 '15 05:10 angelinacc

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

mistic100 avatar Oct 08 '15 11:10 mistic100

Yea, I realized after asking the question but your answer is much better!

Thanks for your help and that would be awesome!

angelinacc avatar Oct 08 '15 15:10 angelinacc

good morning

Thank you very much for the contribution, you have done a fantastic job with all your work, congratulations

regards

davedof avatar Jan 09 '17 22:01 davedof

@davedof happy it helps :-)

mistic100 avatar Jan 10 '17 07:01 mistic100

@mistic100 is this still relevant or did a new version come out?

aryeharmon avatar Feb 20 '17 09:02 aryeharmon

A new version of the picker ? I don't know. Yes it's still relevant

mistic100 avatar Feb 20 '17 09:02 mistic100

@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

aryeharmon avatar Feb 20 '17 09:02 aryeharmon

This feature exists, please read the doc about filters config

mistic100 avatar Feb 20 '17 09:02 mistic100

+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');
        });
    }
});

MikeAlhayek avatar Apr 20 '17 20:04 MikeAlhayek

But you don't need it anymore, the doc says to use input_event: 'dp.change'

mistic100 avatar Apr 21 '17 07:04 mistic100

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 ^_^

cbloss avatar Aug 23 '18 15:08 cbloss