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

getRules is better to return {empty: true} for empty rules #944

Closed tlyau62 closed 2 years ago

tlyau62 commented 2 years ago

For the getRules api, the returned rules array may be better to have the empty rule like the following

{
  "empty": true
}

instead of the null values object to prevent ambiguity.

{
  "id": null,
  "filter": null,
  "value": null
  // ...
}

So, may we have an option like this which also support for backward compatibility?

builder.getRules({
  "emptyRule": true
})
mistic100 commented 2 years ago

if filter is null then then rule is empty, and the rule is only considered empty if the filter is null

you can also already ignore empty rules with skip_empty option

no need for change