API JS Search does not display, in the search bar, the item selected by the user (from the suggested list) while the effective search works perfectly and display on the map the item along with the popup window.
Do you have any idea what I am missing here?
Here is my code:
var search = new Search({
map: map,
enableButtonMode: false,
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: true,
allPlaceholder: "Find PoP, Circuit, CLS, address"
}, "SearchWidget");
var sources = search.get("sources"); //by default there is at least one source: 'ESRI world geocoder'
//Amend some parameters of the default source geocoder (source[0])
sources[0].name = "Place (world geolocator)";
sources[0].placeholder = "Find address or place";
//Push the sources used to search, by default the ArcGIS Online World geocoder is included. In addition we add other feature layers to search into.
// Add layer PoP
sources.push({
featureLayer: new FeatureLayer(layerPoPsConfig.url),
searchFields: ["PoP"],
displayField: "PoP",
exactMatch: false,
outFields: ["*"],
name: "PoP",
suggestionTemplate: "${PoP}, ${Country}", //display in the suggestion menu
placeholder: "Find PoP",
maxResults: 6,
maxSuggestions: 6,
//Create an InfoTemplate
infoTemplate: InfoTemplateLyrPoPs,
enableSuggestions: true,
enableSourcesMenu: true,
enableSuggestionsMenu: true,
minCharacters: 0,
zoomScale: 10000000,
});
//Set the sources above to the search widget
search.set("sources", sources);
search.startup();
Solved! Go to Solution.
Laurent,
Sorry the widget is just not designed for that when using FeatureLayer source. But you can add this feature simply by adding this code:
search.on("select-result", function(evt) {
search.set("value", evt.result.name);
});
laurent,
That is just how the dijit is designed. The search input has never updated to reflect the suggestion menu clicked option.
Hi Robert,
Thanks but why is it the case when I select from the 'world geolocator' ? I would expect we can do the same when the source is another one than this world geolocator.
Laurent,
Sorry the widget is just not designed for that when using FeatureLayer source. But you can add this feature simply by adding this code:
search.on("select-result", function(evt) {
search.set("value", evt.result.name);
});
Hi Robert,
Ok. I just tested it. Working fine.
Many thanks !