I am trying to customize ESRI JS API 3.13 Search widget with custom featurelayers and fields on WAB. However, it seems the search is only picking the default field and ignores others.
sources=[{}], //contains featurelayer url, name and fields
//load ESRI new SEARCH =========================================================
var s = new Search({
showSuggestions: true,
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: false,
map: this.map
}, "esriSearch");
var sources = s.get("sources");
//loop over each layer and add to sources for Search
array.forEach(this.searches, lang.hitch(this, function(sItems, l)
{
if(sItems.fURL){
try
{
sources.push({
featureLayer: new FeatureLayer(sItems.fURL),
searchFields: sItems.fields,
outFields: ["*"],
exactMatch: false,
name: sItems.fName
});
}
catch (error){
console.log(error);
}
}
}));
Realized I should provide data that can be tested
sources.push({
featureLayer: new FeatureLayer("http://services.arcgis.com/DO4gTjwJVIJ7O9Ca/arcgis/rest/services/GeoForm_Survey_v11_live/FeatureServ..."),
searchFields: ["Email", "URL"],
outFields: ["*"],
displayField: "Email",
exactMatch: false,
name: "Point FS",
placeholder: "example: esri"
});
Output:
{"objectIdFieldName":"OBJECTID","globalIdFieldName":"","geometryType":"esriGeometryPoint","spatialReference":{"wkid":102100,"latestWkid":3857},
"fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","sqlType":"sqlTypeOther","domain":null,"defaultValue":null},{"name":"Email","type":"esriFieldTypeString","alias":"Email","sqlType":"sqlTypeOther","length":150,"domain":null,"defaultValue":null}],"exceededTransferLimit":true,
"features":
[{"attributes":{"OBJECTID":6,"Email":"dmillen@latitudegeo.com"}},
{"attributes":{"OBJECTID":8,"Email":"rdejos@utc.wa.gov"}},
{"attributes":{"OBJECTID":16,"Email":"peter.verwey@dpi.nsw.gov.au"}},
{"attributes":{"OBJECTID":48,"Email":"sagunn@unm.edu"}},
{"attributes":{"OBJECTID":53,"Email":"sunilspalkar@gmail.com"}},
{"attributes":{"OBJECTID":91,"Email":"joseph_hayes@co.washington.or.us"}}]}
I was able to get it working, by adding each field and featurelayer combo to source rather than trying to add all fields for that featurelayer. Also had to add, displayfield to the search field.