ESRI Search Widget activeSourceIndex Usage

1006
3
09-15-2018 01:23 PM
NoahHuntington2
New Contributor II

I am looking for some example of setting the default search service to all(feature layer and esri geocoding).  but I also care about the order of the results returned.

I suspect this is accomplished using the activeSource parameter of the search widget. But have not been able to find an example of this implemented.

I have tried implementing like this..

var searchWidget = new Search({    container: "searchDiv",    view: view,    allPlaceholder: "Places or Tyler Communities",    activeSource: 0,    sources: [{        featureLayer: {            url: "https://services5.arcgis.com/6gTxIFMxZdWxCrVQ/arcgis/rest/services/...",            popupTemplate: { // autocasts as new PopupTemplate()                title: "{customer} is  Tyler Connected Community!",                overwriteActions: true            }        },        activeSourceIndex: 1,        searchFields: ["customer", "city", "state"],        displayField: "customer",        exactMatch: false,        outFields: ["*"],        name: "Tyler Communities",        placeholder: "example: city of birmingham",        zoomScale: 500000    }]});

and also like this...

searchWidget.activeSource = 0;

But both return this error...

dojo.js:340 Uncaught TypeError: [accessor] cannot assign to read-only property 'activeSource' of esri.widgets.Search.SearchViewModel

Any help is greatly appreciated.

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Noah,

   As you can see from your error the activeSource property is readonly

activeSourceFeatureLayer|Locatorreadonly

what you need to use is activeSourceIndex which will let you set the number/index of the source.

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#activeSourceI... 

0 Kudos
NoahHuntington2
New Contributor II

Hi Robert. Thank you for the response.  Good to know I was getting close.  I still have not seen activeSourceIndex implemented.  Can you provide an example?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Noah,

  I have not seen any example of it being implemented either. It is a simple property that you set either in the constructor or after creating the widget instance, so nothing special to show in code.

0 Kudos