Hi
I migrated from arcgis java script 4.9 to 4.11, after migration the "Search Widget" don't work!!
Anjelina,
In 4.11 the search widgets layer property takes a Layer class and not specifically a FeatureLayer class so you can not autocast as FeatureLayer as you use to in 4.9 when it was Only expecting a FeatureLayer. So your code would need to look like:
<SPAN class="keyword token">var</SPAN> searchWidget <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Search</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> view<SPAN class="punctuation token">:</SPAN> view<SPAN class="punctuation token">,</SPAN> allPlaceholder<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"search..."</SPAN><SPAN class="punctuation token">,</SPAN> sources<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN> layer<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//Notice the property is called layer Not featureLayer</SPAN> url<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"localhost:6080/arcgis/rest/services/city/FeatureServer/0"</SPAN><SPAN class="punctuation token">,</SPAN> popupTemplate<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// autocasts as new PopupTemplate()</SPAN> title<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"name: {name2} </br>{name_new}"</SPAN><SPAN class="punctuation token">,</SPAN> overwriteActions<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> searchFields<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> displayField<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">,</SPAN> exactMatch<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN> outFields<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> name<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">,</SPAN> placeholder<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"name2"</SPAN><SPAN class="punctuation token">,</SPAN> maxResults<SPAN class="punctuation token">:</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> maxSuggestions<SPAN class="punctuation token">:</SPAN><SPAN class="number token">50</SPAN><SPAN class="punctuation token">,</SPAN> autoNavigate<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="comment token">//enableSuggestions: true //This is not a property of a layerSearchSource</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
var searchWidget = new Search({
view: view,
allPlaceholder: "search...",
sources: [{ featureLayer: { url: "localhost:6080/arcgis/rest/services/city/FeatureServer/0", popupTemplate: { // autocasts as new PopupTemplate() title: "name: {name2} </br>{name_new}", overwriteActions: true } }, searchFields: ["name2"], displayField: "name2", exactMatch: false, outFields: ["name2", "name2"], name: "name2", placeholder: "name2",
maxResults:10, maxSuggestions:50, autoNavigate: true, enableSuggestions: true }, { featureLayer: { url: "localhost:6080/arcgis/rest/services/city/FeatureServer/1", popupTemplate: { // autocasts as new PopupTemplate() title: "name: {cc} </br>{c1cc}", overwriteActions: true } }, searchFields: ["cc"], displayField: "cc", exactMatch: false, outFields: ["cc", "c1cc"], name: "search1", placeholder: "search1", exactMatch: true, zoomScale:13000, maxResults:10, maxSuggestions:50, autoNavigate: true, enableSuggestions: true }] });
view.ui.add(searchWidget, { position: "top-left", index: 2
});
There have been several changes to the search widget and new classes added that the widget now uses. So it is hard to say without seeing your code what the issue is. If you go to the release notes https://developers.arcgis.com/javascript/latest/guide/release-notes/ and search for the word "search" you will find that there are new classes and new methods added in 4.11 and other change in 4.10. https://developers.arcgis.com/javascript/latest/guide/4.10/index.html
But what's the reason of this problem? I searched release note of 4.11 and didn't find any changes in new version(4.11)
Hi anjelina ponkerat,
Your issue is most probably caused by differences between the two versions of the ArcGIS API for JavaScript, version 4.9 and 4.11. So, just migrating to the new version apparently is not enough - because this breaks your application.
The best way forward is to keep the 4.9 app in production until you have rewritten and fully tested the new 4.11 app.
Here you can find a 4.11 sample for the Search Widget | ArcGIS API for JavaScript 4.11
HTH,
Egge-Jan
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.