mistic100 / jQuery-QueryBuilder

jQuery plugin offering an interface to create complex queries
https://querybuilder.js.org
MIT License
1.68k stars 552 forks source link

Filter plugin select2 Uncaught TypeError: element.getAttribute is not a function #924

Closed rickdubiel closed 3 years ago

rickdubiel commented 3 years ago

I've recently upgraded from v2.5.2 to v2.6.0 and ran across a tiny issue with the $.parseHTML update when using the select2 plugin. I believe this issue addresses that update:

https://github.com/mistic100/jQuery-QueryBuilder/issues/905

I narrowed it down to the ruleValueSelect template leaving a single space at the beginning of the template and then $.parseHtml parses that out as an individual array item. When select2 tries to an apply an id to that item by using getAttribute the error occurs. See below:

image

The jQuery docs recommended using jQuery.trim in order to prevent trailing/leading whitespace from being converted to text nodes. That indeed did resolve the issue. Here's a PR with the change:

https://github.com/mistic100/jQuery-QueryBuilder/pull/923

Here's a fiddle with the issue:

https://jsfiddle.net/6qyLvhpb/1/

Just need to make a selection and watch the console to see the error.

Thanks!

mistic100 commented 3 years ago

Thank you for your super complete analysis.

I just released a patch