diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index d7ae2e04..f786a9ca 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -275,7 +275,9 @@ Ox.Filter = function(options, self) { self.options.query.conditions[pos].conditions.splice(subpos, 0, condition); } renderConditions(); - triggerChangeEvent(); + if (!isUselessCondition(pos, subpos)) { + triggerChangeEvent(); + } } function changeConditionKey(pos, subpos, key) { @@ -346,16 +348,37 @@ Ox.Filter = function(options, self) { return type; } - function removeCondition(pos, subpos) { - Ox.print('removeCondition', pos, subpos) + function isUselessCondition(pos, subpos) { subpos = Ox.isUndefined(subpos) ? -1 : subpos; + var conditions = subpos == -1 + ? self.options.query.conditions[pos].conditions + || [self.options.query.conditions[pos]] + : [self.options.query.conditions[pos].conditions[subpos]], + isUseless = false; + Ox.forEach(conditions, function(condition) { + isUseless = Ox.getObjectById( + self.options.findKeys, condition.key + ).type == 'text' + && condition.operator == (self.options.query.operator == '&' ? '' : '!') + && condition.value == '' + return isUseless; + }); + Ox.print('isUseless', isUseless); + return isUseless; + } + + function removeCondition(pos, subpos) { + subpos = Ox.isUndefined(subpos) ? -1 : subpos; + var wasUselessCondition = isUselessCondition(pos, subpos); if (subpos == -1 || self.options.query.conditions[pos].conditions.length == 1) { self.options.query.conditions.splice(pos, 1); } else { self.options.query.conditions[pos].conditions.splice(subpos, 1); } renderConditions(); - triggerChangeEvent(); + if (!wasUselessCondition) { + triggerChangeEvent(); + } } function renderButtons(pos, subpos) {