Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form filter - Also search for NULL values when empty string is checked #5269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions assets/src/legacy/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ var lizLayerFilterTool = function () {
var filter = null;
var field = field_item['field'];
if (clist.length) {
// Check if the value '' is present. If so, we should also search for NULL
let hasEmptyValue = false;

// If there is a separator in the field values, and we need
// to explode the values into single items, we need to use
// LIKE statements joined with OR
Expand All @@ -669,17 +672,35 @@ var lizLayerFilterTool = function () {
}
for (var i in clist) {
var cval = clist[i];
// If cval is '', we should store this information
if (cval === '') {
hasEmptyValue = true;
}

// Create the filter for this value
filter += sep + '"' + field + '"' + " " + lk + " '%" + cval + "%' ";
// We need to use a OR to display features with
// 'Theatre, Culture' or 'Theatre', or 'Culture, Information'
// When 'Theatre' and 'Culture' are checked in the list
sep = ' OR ';
}
// Add NULL values
if (hasEmptyValue) {
filter += ` OR "${field}" IS NULL `;
}
filter += ' ) ';
} else {
// Search for empty values (to add the rule OR "field" IS NULL )
if (clist.includes('')) {
hasEmptyValue = true;
}
// If there is not separator in the field values, use IN to get all features
// corresponding to one of the checked values
filter = '"' + field + '"' + " IN ( '" + clist.join("' , '") + "' ) ";
// Add NULL values
if (hasEmptyValue) {
filter = ` ( ${filter} OR "${field}" IS NULL ) `;
}
}
}
globalThis['filterConfig'][field_item.order]['filter'] = filter;
Expand Down
Loading