Question on how to use dijit/form/select in Arc JS API

5103
11
Jump to solution
05-29-2015 07:17 AM
JeffJohnson1
New Contributor II

I'm brand new to javascript, dojo and HTML and I've searched everywhere for examples of this and cannot find any.

I have a map with some feature points and a find task to highlight the feature points on the map, and display them in a grid with it's field attributes. This works great when I specify the search field as:

findParams.searchFields = ["LOCATION"];

But if I add:

findParams.searchFields = ["LOCATION", "MODEL_NUM"];

The grid displays results from multiple fields (ie. searching for attributes in LOCATION "A" would also find attributes in MODEL_NUM containing the letter "A"). So I decided to add a drop down menu select to specify which field to search in (one at a time) so the results are more precise.

So I added the following dijit:

<select id="fieldSelect" data-dojo-type="dijit/form/Select" name="fieldSelect">

          <option value="" selected="selected">Select a field</option>

          <option value="MODEL_NUM">Model Number</option>

          <option value="LOCATION">Location</option>

          <option value="NUM_DEFICIENCIES">Number of Deficiencies</option>

          <option value="INSTALL_DATE">Install Date</option>

</select>

I then modified the search field statement to:

findParams.searchFields = "[" + "\"" + dom.byId("fieldSelect").value + "\"" + "]";

When I click my search button I get an Uncaught TypeError: a.join is not a function (FindParameters.js:5)

I hope this is enough information. Does anyone have a solution or a recommendation?

Thanks.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When using a dijit, you usually have to locate in the dom by using dijit/registry

Try using var selectedField = registry.byId('fieldSelect').value;

View solution in original post

11 Replies
thejuskambi
Occasional Contributor III

try this out

findParams.searchFields = [dom.byId("fieldSelect").value];

BillDaigle
Occasional Contributor III

You're creating a string instead of an array.

Try:

findParams.searchFields = [];
findParmas.searchFields.push(dom.byId("fieldSelect").value);
thejuskambi
Occasional Contributor III

you need to push it to searchFields not findParams... small typo

BillDaigle
Occasional Contributor III

Ah yes...thanks for heads up.  I will edit accordingly!

0 Kudos
JeffJohnson1
New Contributor II

Thanks to both of your replies.

I tried each, and while they both run smoothly without errors, findParams.searchFields is still not getting anything passed to it.

I tried the following example I found:

var selectedField = document.getElementById('fieldSelect').value;

var index = selectedField.options[selectedField.selectedIndex].value;

As well as:

var selectedField = dom.byId('fieldSelect').value;

In the Chrome developer tools debugger, when I created a breakpoint at that line and executed the statement, both examples had the value of selectedField as 'undefined'.

Is this an issue of not getting the value from the drop down select dijit?

Thanks.

0 Kudos
KenBuja
MVP Esteemed Contributor

When using a dijit, you usually have to locate in the dom by using dijit/registry

Try using var selectedField = registry.byId('fieldSelect').value;

JeffJohnson1
New Contributor II

This does work! The registry.byId is showing the field name from the drop down menu value. But the grid is still displaying the wrong results when I run the find task.

When I check the value of searchFields after this line is executed:

findParmas.searchFields.push(registry.byId("fieldSelect").value);

The array length is still 0.

Unfortunately I can't setup a sandbox as the server running the map service is private.

thejuskambi
Occasional Contributor III

Can you provide the code atleast. I think something might be wrong in the flow

0 Kudos
thejuskambi
Occasional Contributor III

If you could setup a sandbox or provide us the code it would be really helpful. If you cannot.

check if the dom.byId("fieldSelect") is returning the proper node you need. also the getElementById returns an element. I think you dont need to get value of it. like below

var selectedField = document.getElementById('fieldSelect');

var index = selectedField.options[selectedField.selectedIndex].value;

Also, check registry.byId. make sure you add the registry module to require.