Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

it seems like OpenLayers.Filter.Comparison.LIKE doesn't filter special characters! for example,

filter = new OpenLayers.Filter.Comparison({ 
    type: OpenLayers.Filter.Comparison.LIKE, 
    property: 'name', 
        value: 'blue' 
    }) 

this will work fine. but:

filter = new OpenLayers.Filter.Comparison({ 
    type: OpenLayers.Filter.Comparison.LIKE, 
    property: 'name', 
        value: 'light-blue' 
    }) 

this will cause an error because of the -

it also can't deal with dots

what can I do to fix that ?

EDIT

I tried:

var filter = new OpenLayers.Filter.Comparison(
  { type: OpenLayers.Filter.Comparison.LIKE,
    property: 'name',
    value: input }
);
filter.value2regex( "-","." ); 

I wanted to escape those two characters from any value. but nothing changes.

share|improve this question
add comment

2 Answers

You can use an escape character in your filter to 'hide' special characters. The docs aren't very clear but it looks like the default escape character is !

In an ideal world you could just set the the single and multiple wild cards to something that doesn't occur in your strings but there doesn't seem to be an option for that :-(

share|improve this answer
    
Thank you! Updated My Post. would you please take a look? –  Shadin Jan 5 '13 at 18:05
add comment

I could not found a problem in my tests with the "light-blue" value.

var filter = new OpenLayers.Filter.Comparison(
  { type: OpenLayers.Filter.Comparison.LIKE, property: 'name', value: 'light-blue' }
);
filter.evaluate( { name: 'light-blue' } );

The value property is a regexp string. You could reference the javascript documentation for valid values: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp .

So if you want to match the literal character "-" you could add escapes to your regexp:

var filter = new OpenLayers.Filter.Comparison(
  { type: OpenLayers.Filter.Comparison.LIKE, property: 'name', value: 'light\\-blue' }
);
filter.evaluate( { name: 'light-blue' } );
share|improve this answer
    
Thank you. but what if I want to escape a character from any value that user types? I updated my post. would you please take a look? –  Shadin Jan 5 '13 at 18:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.