Select to view content in your preferred language

eSearch Widget working with sub-strings

987
3
02-29-2012 06:33 AM
TristanForward2
Emerging Contributor
Here is what I am trying to do.

Within the SearchWidget.xml

I want the user to input the search like the example shown below. A function is called passing the user inputted value. The function then parses the string into sub-substrings and re-arranges the sting to match how the data is shown in the database in this case "23-J, 104-A-10" would become "104A10023".

What I'm asking is where would I put this function in the SearchWidget.mxml. Your thoughts/ideas?

<expressions>
    <expression alias="Grid Unit"
     textsearchlabel="Search by Grid Unit [Example: 23-J, 104-A-10]:">Grid_ID LIKE ('%[value]%')</expression>
   </expressions>
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Tristan,

   In the queryFeaturesText function somewhere in this block:

                    var myPattern:RegExp = /\[value\]/g;
                    var expr:String;
                    var eVal:String;
                    if (txtSearch.visible){
                        if(queryExpr != "[value]")//meaning an open SQL expression
                            eVal = txtSearch.text.replace("'","''");
                        else
                            eVal = txtSearch.text;
                        expr = queryExpr.replace(myPattern, eVal); 
                    }else{
                        eVal = cbSearch.selectedItem.value.replace("'","''");
                        expr = queryExpr.replace(myPattern, eVal); 
                    }
                    query.where = expr;
0 Kudos
TristanForward2
Emerging Contributor
I think I found the place in the code, similar to your example but with some changes. From what I gather I can use the string.replace as a starting point for my function. Since the repl parameter in the .replace can also be a function. See below, sound correct?

if (queryLayer)
    {
     var query:Query = new Query();
     var myPattern:RegExp = /\[value\]/g;
     var expr:String;
     
     // adds quotes to the string to be used for SQL query
     value = value.replace("'","''");
     expr = queryExpr.replace(myPattern, mySubStringFunctionResult);
     query.where = expr;
     query.outSpatialReference = map.spatialReference;
     if(queryDefExpr != "")
      queryLayer.definitionExpression = queryDefExpr;
     queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields)); 
     showMessage(loadingLabel, true); 
     showStateResults();
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tristan,

   You must be using some older version of the eSearch Widget than... What you have will likely work but you are negating this line where I handle escaping single quotes in name like o'Keefe.

value = value.replace("'","''");
0 Kudos