Hi @eherve,
The default booleanHandler returns false when filtering for 'false' value so the conditions field is undefined, maybe because no conditions is added:
// Default boolean handler
function(field, search) {
var value;
search.forEach(function(chunk) {
if (/^true$/i.test(chunk)) {
value = true;
} else if (/^false$/i.test(chunk)) {
value = value || false;
}
});
return value == undefined ? undefined : value;
}
// addConditions in searchCriteria
function addConditions(searchCriteria, field, conjunctions, disjunctions) {
var condition = ConditionBuilder.getGeneralSearch(field,
searchCriteria.search, searchCriteria.options);
if (condition) {
var element = {};
element[field.path] = condition;
disjunctions.push(element);
}
condition = ConditionBuilder.getFieldSearch(field, searchCriteria.options);
if (condition) {
var element = {};
element[field.path] = condition;
conjunctions.push(element);
if (field.arrayPath) addAggregate(searchCriteria, field, condition);
}
}
I have overwrite the default boolean handler with my own version and works right. Just changed the last line to return {$in: [value]}
options.handlers = {
Boolean: function (field, search) {
var value;
search.forEach(function (chunk) {
if (/^true$/i.test(chunk)) {
value = true;
} else if (/^false$/i.test(chunk)) {
value = value || false;
}
});
return value == undefined ? undefined : {$in: [value]};
}
};
Also if we want consider 'false' as 'not true' we can use this other version:
options.handlers = {
Boolean: function (field, search) {
var value;
search.forEach(function (chunk) {
if (/^true$/i.test(chunk)) {
value = true;
} else if (/^false$/i.test(chunk)) {
value = value || false;
}
});
return value == undefined ? undefined : {$in: value ? [value] : [null, value]};
}
};
What do you think to include one of the proposed boolean handlers as the default?
Hi @eherve, The default booleanHandler returns false when filtering for 'false' value so the conditions field is undefined, maybe because no conditions is added:
I have overwrite the default boolean handler with my own version and works right. Just changed the last line to return {$in: [value]}
Also if we want consider 'false' as 'not true' we can use this other version:
What do you think to include one of the proposed boolean handlers as the default?