Select to view content in your preferred language

Populate dropdown, specifying label and values coming from different attributes

7152
21
Jump to solution
09-25-2013 01:20 PM
TracySchloss
Frequent Contributor
I have a layer of school districts that contains both the school district name and a district ID number.  I have a layer of schools which contains just the district ID number.

I'm populating my dijit.form.Select from the attributes of the school district layer.  I need the list to appear as district names, but at the same time, it would be nice if the values were the district IDs.  Then I could fire off a query on the school layer using a where clause without having to do any other hoop jumping (I think).  This code works to populate my dropdown, I'd just like it to be a little more functional. 

function populateDropDownList(){     var queryTask = new QueryTask(educationLayer.url + "/3");     var query = new Query();     query.outFields = ["DIST_NAME"];     query.where = "1=1";     query.returnGeometry = false;       queryTask.on('complete', resultsHandler);     queryTask.on('error', errorHandler);     queryTask.execute(query); }  function resultsHandler(results){     select = registry.byId("distSelect");// a dijit.form.Select      districtList.length = 0;     var numResults = results.featureSet.features.length;     for (var j = 0; j < numResults; j++) {         var distName = results.featureSet.features.attributes.DIST_NAME; //note the attribute name for the district code is DIST_CODE         districtList.push(distName);     }     districtList.sort();     var testList = arrayUtil.map(districtList, function (item, index){     return {         label:item,         value:item         };     });     select.addOption(testList); }
0 Kudos
21 Replies
JasonZou
Regular Contributor
Tracy, you should set labelAttr and searchAttr the same value as George mentioned before.

select.set ("labelAttr", "label");
select.set ("searchAttr", "label");
0 Kudos
TracySchloss
Frequent Contributor
OK, I was thinking if I used Label for both those, then somehow I wasn't making use of the value anywhere at all.  Now I just need to look at my prompt a little differently.   I started out with a single option "Pick a district" and rely on the function to add all the names below it. 

When you click in the box as if to type to start a serach, it doesn't clear the prompt, you're just type the letter in front of the Pick a district, so you can something like DPick a district, which of course yields nothing.  I need something to clear 'onClick' or something like that.
0 Kudos