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

QueryBuilder.updateRuleFilter is deleting "user" data

Open jeremieroy opened this issue 6 years ago • 3 comments

Hi, we currently faced an issue were the data from our custom plugins were deleted by the querybuilder core system. From my understanding the data associated with a rule is meant to be managed by external components like plugins and should not be deleted by the querybuilder (as long as the rule is not deleted or similar). But I may misunderstand the intent.

The situation comes from: In QueryBuilder.prototype.updateRuleFilter https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/src/core.js#L756

// clear rule data if the filter changed
if (previousFilter && rule.filter && previousFilter.id !== rule.filter.id) {
        rule.data = undefined;
}

As far as I can tell this is the only place where the data (as "user" data) is deleted. Maybe the intent was to clear the rule value and it was a typo ?

As a (temporary?) workaround I am overriding the updateRuleFilter prototype locally to not have this behavior.

jeremieroy avatar May 17 '19 12:05 jeremieroy

I could do a PR, but I would just delete these 3 lines, so I think it is better to understand the original intent first ;)

jeremieroy avatar May 21 '19 09:05 jeremieroy

The original feature was to transmit data from filters to rules, so removing this test will break it as it it will always merge with previous data.

A new conception, with new options and new events has to be done in order to fulfill both the original feature and what you want.

mistic100 avatar May 21 '19 10:05 mistic100

Thanks for answering :)

We extensively extended the querybuilder using nearly only plugins and a bit of jquery extends. We had to patch some internal prototypes because we have async query in there, but that's not relevant in this discussion. Overall, the only change we made that doesn't seems to be in the spirit of the querybuilder is the 3 lines above.

I assume the problem is that we have some kind of "category" before the filter and operator, and this "category" is stored in the data field. Screenshot from 2019-05-21 22-13-49

Here: "position" is a "category" and "speed" is the filter. When you change the "category", a new set of filters is downloaded and proposed. But off course we don't want to lose the "category" information if you change the filter ^^

So we store metadata at the rule level while the data field is intended to only contains data relevant to the filter, am I right ? The documentation could be misleading I think:

Additional data not used by QueryBuilder but that will be added to the output rules object. Use this to store any functional data you need.

jeremieroy avatar May 21 '19 20:05 jeremieroy