mistic100 / mistic100/jQuery-QueryBuilder
Error in .on('rulesChanged.queryBuilder') function when calling getRules
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 544
- PR merge metrics
- No merged PRs in 30d
Description
Plugin initializes normally, and can load previously saved rules at initialization without problem.
I've added an auto-save feature using the "rulesChanged.queryBuilder API Event as follows:
$('#queryBuilder').on('rulesChanged.queryBuilder', function(evt) {
const blockRules = $('#queryBuilder').queryBuilder('getRules')
console.log('Rule Changed!', blockRules)
if (blockRules) {
//Save the rule
//saveRules function here
}
})
The problem arises if I try to clear or change the ruleset on an already initialized queryBuilder:
$('#queryBuilder').queryBuilder('clear')
or
$('#queryBuilder').queryBuilder('setRules', rules, true)
Either of the calls above will trigger the rulesChanged event, resulting in the getRules method crashing with the error:
/node_modules/jQuery-QueryBuilder/dist/js/query-builder.js:1697 Uncaught TypeError: Cannot read property 'each' of null
at parse (/node_modules/jQuery-QueryBuilder/dist/js/query-builder.js:1697)
at QueryBuilder.validate (/node_modules/jQuery-QueryBuilder/dist/js/query-builder.js:1749)
at QueryBuilder.getRules (/node_modules/jQuery-QueryBuilder/dist/js/query-builder.js:1779)
I can probably work around it by adding an ugly try/catch or using beforeClear to destroy the listener and rebuild it again, but there really should be an integrated solution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the rulesChanged.queryBuilder handler and trace the getRules call through dist/js/query-builder.js at parse, validate, and getRules, using the reported error at line 1697 as the entry point. Reproduce the issue with clear and setRules(..., true) after initialization; done means those operations can trigger rulesChanged without getRules crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jquery
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100