mistic100 / jQuery-QueryBuilder

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

TypeError: Cannot read properties of undefined (reading 'id') #975

Closed felipecaparelli closed 1 year ago

felipecaparelli commented 1 year ago

Error during component construction

When the component is reading the rules data, it fails with the following error:

TypeError: Cannot read properties of undefined (reading 'id')
    at Rule.Node (query-builder.standalone.js:3694:22)
    at new Rule (query-builder.standalone.js:4060:10)
    at Group.addRule (query-builder.standalone.js:3951:28)
    at QueryBuilder.addRule (query-builder.standalone.js:1376:24)
    at query-builder.standalone.js:2231:30
    at Array.forEach (<anonymous>)
    at add (query-builder.standalone.js:2203:20)
    at QueryBuilder.setRules (query-builder.standalone.js:2283:6)
    at QueryBuilder.init (query-builder.standalone.js:853:14)
    at $.fn.queryBuilder (query-builder.standalone.js:4153:17)
{
    "condition":"OR",
    "rules":[
    {"id":"CUSTOMER.ACCOUNT_STATUS","field":"CUSTOMER.ACCOUNT_STATUS","type":"string","input":"text","operator":"equal","value":"Active"},
    {"id":"CUSTOMER.ACCOUNT_STATUS","field":"CUSTOMER.ACCOUNT_STATUS","type":"string","input":"text","operator":"equal","value":"New"}
    ]
}

model = self.addRule(group, item.data, self.parseRuleFlags(item));

But what is really causing the component to fail, is that inside the function setRoot(addRule, data, flags), the parsing to get the elements is returning a text node:

queryBuilder_issue_06-29-2023

The code returning this empty node is $($.parseHTML(this.getGroupTemplate(group_id, 1)));

queryBuilder_issue2_06-29-2023

And follow below the JSON generated to build the component:

{
    "plugins":{"bb-datepicker":{"format":"MM/dd/yyyy"},"bb-in-collection":null,"sortable":{"icon":"grip-handle"}},
    "filters":[
        {"id":"DECISION.ALWAYS_FALSE","label":"DECISION.ALWAYS_FALSE","type":"boolean","input":"radio","operators":["equal"],"values":[{"true":"True"},{"false":"False"}],"operandType":"DECISION"},
        {"id":"DECISION.ALWAYS_TRUE","label":"DECISION.ALWAYS_TRUE","type":"boolean","input":"radio","operators":["equal"],"values":[{"true":"True"},{"false":"False"}],"operandType":"DECISION"}
        ],
    "rules":{"condition":"OR","rules":[{"id":"CUSTOMER.ACCOUNT_STATUS","field":"CUSTOMER.ACCOUNT_STATUS","type":"string","input":"text","operator":"equal","value":"Active"},{"id":"CUSTOMER.ACCOUNT_STATUS","field":"CUSTOMER.ACCOUNT_STATUS","type":"string","input":"text","operator":"equal","value":"Change_Of_Service"}]},"templates":{"filterSelect":"                            {{ var optgroup = null; }}                             <div class=\\"rule-filter-wrapper\\" ng-click=\\"vmEditor.openDecisionExprOperandSelection('{{= it.rule.id }}', $event)\\">                                 <input class=\\"form-control\\" name=\\"{{= it.rule.id }}_filter\\" type=\\"text\\">                                 <img class=\\"decision-hamburger\\" src=\\"img/decision-hamburger.svg\\"></i>                             </div>"},
    "display_errors":false
}

In the meantime, is there any way for me to override this function to avoid waiting for this fix (if this is really a bug)? Thanks

felipecaparelli commented 1 year ago

This issue is only occurring in the version 2.6.2, but is working fine in the version 2.5.2