autoSelect on Search dijit not working

4600
7
05-19-2015 09:02 AM
JeffMitzelfelt
New Contributor III

I don't appear to be able to get the autoSelect on the Search to work as I expect it should work.

I expect that as I enter an address and as the suggestion list is filled the top suggestion will be selected and used for the search when I press the enter key.

Here is a jsbin with a map that will pull suggested addresses from Illinois.

This is the code that defines the parameters of the Search dijit.

  var search = new Search({
      autoNavigate: true,
      autoSelect: true,
      enableHighlight: true,
      enableInfoWindow: false,
      map: map,
      enableButtonMode: true,
      expanded: false,
      minCharacters: 3
    },
    "searchDiv"
  );

When I type in an address like "1021 N Grand Ave E, Sp" the top suggestion is "1021 N Grand Ave E, Springfield, Illinois, USA" but when I hit Enter I get a response box with 'No results - There were no results found for "1021 N Grand Ave E, Sp".'

Any Insights?

Message was edited by: Jeff Mitzelfelt OOPS Updated Link

0 Kudos
7 Replies
JeffJacobson
Occasional Contributor III

I am able to reproduce what you are describing.

However, if you either click on the suggestion in the list, or push the down arrow to select the suggestion and then press Enter, it will take you to the correct location.

Someone at Esri would need to tell you if this is a bug or not.

0 Kudos
JeffMitzelfelt
New Contributor III

It appears that the autoSelect works fine without setting the extent on the search widget. Thanks goes to Kristian Ekenes of Esri for the answer.

Hi Jeff,

Thanks for sending us the feedback. I can reproduce this using your sample. It looks like the World Geocoding Service will get a response from suggestLocations, but not the “search” when you have an extent set on the source:

  1. search.sources[0].searchExtent = searchExtent;

.......

Kristian Ekenes | Product Engineer | ArcGIS JavaScript API

  ESRI | 380 New York Street, Redlands, CA 92373

On the list for a fix.

0 Kudos
BryanMc
Occasional Contributor

Great to hear the issue is being tracked as I just stumbled on the Extent issue in my test app. Wondering if Kristian Ekenes​ might be able to provide a BUG or NIM # so we can track?

Many thanks!

0 Kudos
KristianEkenes
Esri Regular Contributor

Unfortunately, I'm not able to provide a BUG or NIM# for tracking. Whoever submits the issue to support should be able to provide that number.

After looking into this issue further, it's worth noting that the suggest function behaves differently than the actual "search" or "findAddressCandidates" function. Typing "1021 N Grand Ave E, Sp" into the search bar automatically inputs that text to the suggest() function. When you hit ENTER or the search button, it sends that same exact text to the findAddressCandidates() function. Both suggest() and findAddressCandidates() have different logic and therefore yield different results.

The reason, no results are returned in the above example is because the top result from findAddressCandidates() is located outside the searchExtent even though the top result from suggest() IS located inside the search extent. I know...it's weird behavior, but that's what's going on behind the scenes. So when autoSelect is set to true, it's not selecting the first suggestion, it's selecting the first result returned from the geocode. The documentation can be updated to make that more clear.

To make sure the text from a suggestion is used for the findAddressCandidates() function, you must click on the text for it to search the suggestion properly. I hope this explanation helps.

0 Kudos
AkshayHarshe
Esri Contributor

Hi Jeff,

I agree with Kristian.

Also, If we look at AutoSelect function specifically, I don't think we can log a bug against that because this function is dependent on FindAddressCandidate task's results and on correct results this works completely fine.

The suggestions given in the box below are result of the Suggest task and actual address is returned by the FindAddressCandidates. If you are writing a specific address and you hit ENTER button you are not selecting the suggestion, instead, It will always give a priority to the text that you have typed in the box (Even if it is spelled incorrect) over what is the first suggestion and send that to the FindAddressCandidate. So, I might not see this as bug, It will probably just by design. Kristian Ekenes​ can you provide some insight on that.

Also, if you type the address that you have given( "1021 N Grand Ave E, Sp") in GOOGLE Maps  and hit ENTER button it will not select the first suggestion and will behave identically returning no results.

If you want it to customize and add a behavior like that I would recommend checking out Suggest-Results event. You may be able to get the first value and complete the search box on "TAB" Button click leaving the enter button to function as it is.

Let me know your thoughts.

Thanks,

Akshay

Thanks,
Akshay Harshe
0 Kudos
KristianEkenes
Esri Regular Contributor

Thanks, Akshay. In addition to understanding the differences between suggest() and findAddressCandidates(), I think the documentation currently doesn't do a good job at conveying the purpose of autoSelect. This will be updated so that it makes more sense.

The purpose of autoSelect isn't to select the first suggestion, geocode it, and zoom to it. Rather, it is to geocode and zoom to the first result returned from entering the text exactly as it appears in the search box. This text is sent directly to findAddressCandidates() and doesn't necessarily return the same result as the top suggestion since both are sent to different endpoints. The suggestions listed below the text box as you type are merely that - suggestions. Those results will not be used to geocode unless you click on one of them or select it using your keyboard. Merely hitting enter will only take what is already inside the text box.

autoSelect is set to true by default. If you set it to false, you will notice that the findAddressCandidates() function is called, but the top geocoded result is not selected or zoomed to. It is up to the developer to use the results however they want. The results can be accessed using the search-results event: Search | API Reference | ArcGIS API for JavaScript . autoSelect is true by default because in most cases the top result is what the user wants to zoom to.

AkshayHarshe
Esri Contributor

I agree with your opinion Kristian Ekenes. Also, documentation is not very clear on explaining details about autoSelect.

Thanks,
Akshay Harshe
0 Kudos