My code is following:
var filterParams = {
'FILTER': null,
'CQL_FILTER': null,
'FEATUREID': null
};
if (filter.length > 0) {
filterParams["CQL_FILTER"] = filter;
lyr.getSource().updateParams(filterParams);
}
else {
alert ('Filter is empty')}
When the filter string is invalid, for example, PARAMETER VALUE (without =), lyr.getSource().updateParams(filterParams) silently fails and users don't know that their input is invalid. I'd like to alert the user if the filter is invalid
Open Layers 2 had a means to verify a CQL expression was valid as shown below:
var format = new OpenLayers.Format.CQL();
var filter;
try {
filter = format.read(cql.value);
} catch (err) {
output.value = err.message;
Does ol3, ol4, or ol5 have similar functionality?
Even if the expression is valid, lyr.getSource().updateParams(filterParams) silently fails if the fields referenced are incorrect This post describes how to return a list of fields in the layer with WFS or WMS. From that, it would take some work to parse the CQL filter to validate the fields.
Is it asking to much to expect lyr.getSource().updateParams(filterParams) to return an error message so developers don't have to code substantial error checking?