Skip to content

Commit 97a6b0f

Browse files
committed
[invert plugin] add "no_invert" filter option + do not invert when the operator is not in the list
1 parent d762d58 commit 97a6b0f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/plugins/invert/plugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ QueryBuilder.extend({
9797
if (options.silent_fail === undefined) options.silent_fail = false;
9898

9999
if (node instanceof Group) {
100+
// invert group condition
100101
if (this.settings.conditionOpposites[node.condition]) {
101102
node.condition = this.settings.conditionOpposites[node.condition];
102103
}
103104
else if (!options.silent_fail) {
104105
error('Unknown inverse of condition "{0}"', node.condition);
105106
}
106107

108+
// recursive call
107109
if (options.recursive) {
108110
node.each(function(rule) {
109111
if (options.invert_rules) {
@@ -115,9 +117,14 @@ QueryBuilder.extend({
115117
}
116118
}
117119
else if (node instanceof Rule) {
118-
if (node.operator) {
120+
if (node.operator && !node.filter.no_invert) {
121+
// invert rule operator
119122
if (this.settings.operatorOpposites[node.operator.type]) {
120-
node.operator = this.getOperatorByType(this.settings.operatorOpposites[node.operator.type]);
123+
var invert = this.settings.operatorOpposites[node.operator.type];
124+
// check if the invert is "authorized"
125+
if (!node.filter.operators || node.filter.operators.indexOf(invert) != -1) {
126+
node.operator = this.getOperatorByType(invert);
127+
}
121128
}
122129
else if (!options.silent_fail){
123130
error('Unknown inverse of operator "{0}"', node.operator.type);

0 commit comments

Comments
 (0)