ComboBox queryExp

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ComboBox queryExp

Arjun Dongre

Hello,

   I am trying to use the query expression for autocomplete to build an address search combobox. To populate my Memory, I am querying to a database on each “on-change” event. Once the pertinent address is located, the on key up event is used to do other work. When all those processes are complete I would like the memory to be erased completely so it doesn’t just continually build up. Additionally, the user should be able to continue search for another address. The problem I am running into with the query expression is that it is not allowing for new data to be added to the memory after the first search. Not sure how to fix.

 

Thanks!

 

       var addressSearch = new ComboBox({

              id: "addressSearch",

              intermediateChanges: true,

              required: false,

              placeHolder: "Search by Address",

              autoComplete:false,

              scrollOnFocus:true,

              store:addresses,

              queryExpr:"*${0}*",

              searchAttr: "id",

              onChange: function(){

                     var addQueryTask = new QueryTask(queryURL);

                     var addQuery = new Query();

                     addQuery.returnGeometry = false;

                     addQuery.where = "ADDRESS_FULL LIKE '%" + this.value + "%'" ;

                     addQuery.outFields = ["ADDRESS_FULL", "PIN", "ZIP"];

                     addQueryTask.execute(addQuery, function(results){

                           var features = results.features;

                           var i = 0;  

                           for (i; i<features.length; i++){

                                  var tempCommunity = city_zip[features[i].attributes.ZIP];

                                  addresses.put({name: features[i].attributes.PIN, id:features[i].attributes.ADDRESS_FULL+", "+tempCommunity});

                           }

                     });

              },    

              onKeyUp:function(evt){

                     var searchObject={};

                     if(evt.keyCode == 13){

                           var addQueryTask = new QueryTask(queryURL);

                           var addQuery = new Query();

                           map.graphics.clear();

                           var tempPin = addresses.get(dijit.byId("addressSearch").value).name;

                           addQuery.returnGeometry = true;

                           addQuery.where = "PIN LIKE '"+tempPin+"'" ;

                           addQuery.outFields = ["PIN"];

                           addQueryTask.execute(addQuery, function(result){

                                  console.log(result)

                                  map.setExtent(result.features[0].geometry.getExtent());

                                  dijit.byId("addressSearch").reset();

                                  addresses=new Memory();

                                                             

                           });

                     }

              }

       }, "addressSearch").startup;

 

 

 

Arjun Dongre

Software Systems Engineer,

GIS Services

100-A Southwest Blvd

PO Box 389

Newton, NC 28658

828.465.8397

GISLogo001.bmp

 


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: ComboBox queryExp

denov

DO NOT DO THIS!

you're asking for sql injection attacks.  there's nothing from stopping me from overriding the those queries with Tamper (https://chrome.google.com/webstore/detail/tamper-chrome-extension/hifhgpdkfodlpnlmlnmhchnkepplebkb?hl=en)

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=arcgis+sql+injection

on the questions about re-assigning a new store on the keyUp hander, you should be able to do addresses.setData([]).   take a look at the source for Memory.js

and then your code would be much easier to maintain and to debug if you do not use anon functions. also using attach-points vs IDs can make life a lot easier.




- deno
-- 
www.fullstacksystems.com


On 2/6/2017 12:14 PM, Arjun Dongre wrote:

Hello,

   I am trying to use the query expression for autocomplete to build an address search combobox. To populate my Memory, I am querying to a database on each “on-change” event. Once the pertinent address is located, the on key up event is used to do other work. When all those processes are complete I would like the memory to be erased completely so it doesn’t just continually build up. Additionally, the user should be able to continue search for another address. The problem I am running into with the query expression is that it is not allowing for new data to be added to the memory after the first search. Not sure how to fix.

 

Thanks!

 

       var addressSearch = new ComboBox({

              id: "addressSearch",

              intermediateChanges: true,

              required: false,

              placeHolder: "Search by Address",

              autoComplete:false,

              scrollOnFocus:true,

              store:addresses,

              queryExpr:"*${0}*",

              searchAttr: "id",

              onChange: function(){

                     var addQueryTask = new QueryTask(queryURL);

                     var addQuery = new Query();

                     addQuery.returnGeometry = false;

                     addQuery.where = "ADDRESS_FULL LIKE '%" + this.value + "%'" ;

                     addQuery.outFields = ["ADDRESS_FULL", "PIN", "ZIP"];

                     addQueryTask.execute(addQuery, function(results){

                           var features = results.features;

                           var i = 0;  

                           for (i; i<features.length; i++){

                                  var tempCommunity = city_zip[features[i].attributes.ZIP];

                                  addresses.put({name: features[i].attributes.PIN, id:features[i].attributes.ADDRESS_FULL+", "+tempCommunity});

                           }

                     });

              },    

              onKeyUp:function(evt){

                     var searchObject={};

                     if(evt.keyCode == 13){

                           var addQueryTask = new QueryTask(queryURL);

                           var addQuery = new Query();

                           map.graphics.clear();

                           var tempPin = addresses.get(dijit.byId("addressSearch").value).name;

                           addQuery.returnGeometry = true;

                           addQuery.where = "PIN LIKE '"+tempPin+"'" ;

                           addQuery.outFields = ["PIN"];

                           addQueryTask.execute(addQuery, function(result){

                                  console.log(result)

                                  map.setExtent(result.features[0].geometry.getExtent());

                                  dijit.byId("addressSearch").reset();

                                  addresses=new Memory();

                                                             

                           });

                     }

              }

       }, "addressSearch").startup;

 

 

 

Arjun Dongre

Software Systems Engineer,

GIS Services

100-A Southwest Blvd

PO Box 389

Newton, NC 28658

828.465.8397

GISLogo001.bmp

 





--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest