<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Search component with custom source in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651530#M87629</link>
    <description>&lt;P&gt;Thank you for your response&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt;.&amp;nbsp; I should perhaps be more clear on what I'm trying to accomplish.&amp;nbsp; Given a field in a feature layer, after the user types the min suggested characters, I want them to be presented with the list of unique values observed in the data.&amp;nbsp; I think that's pretty clear and is what's already happening in both my example and your example.&amp;nbsp; However, what I really want to do is get back the value that the user selected and do something with it.&amp;nbsp; My example prints the value to the console (but it's always the first value and not the one they selected) whereas your example zooms to the selected elements.&amp;nbsp; Perhaps I'm going about this all wrong.&amp;nbsp; much appreciated!&lt;/P&gt;</description>
    <pubDate>Thu, 18 Sep 2025 16:26:34 GMT</pubDate>
    <dc:creator>GaryB</dc:creator>
    <dc:date>2025-09-18T16:26:34Z</dc:date>
    <item>
      <title>Search component with custom source</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651307#M87627</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to use a layer as a custom source for a search component and am unable to get it working.&amp;nbsp; I did have this working without components in older versions of the API but having no luck now.&amp;nbsp; In a nutshell the custom layer source is looking at one field to bring back values seen.&amp;nbsp; If for example you type MBTA in the search window you should see many options, but regardless of which one I select it always returns the first one (currently printing to the console window).&amp;nbsp; There's probably an easy solution but I just cant get it working. Thanks!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import './style.css'

import FeatureLayer from '@arcgis/core/layers/FeatureLayer.js'
import LayerSearchSource from '@arcgis/core/widgets/Search/LayerSearchSource.js'
import "@arcgis/map-components/components/arcgis-map";
import '@arcgis/map-components/components/arcgis-search'

const arcgisMap = document.querySelector('arcgis-map')

arcgisMap.addEventListener('arcgisViewReadyChange', (event) =&amp;gt; {
  
    let MapComponent = event.target

    // ADD THE LAYER
    let railLayer = new FeatureLayer({ url: 'https://services.arcgis.com/xOi1kZaI0eWDREZv/arcgis/rest/services/NTAD_North_American_Rail_Network_Lines/FeatureServer/0' })
    MapComponent.map?.add(railLayer)

    // SET UP THE CUSTOM SEARCH SOURCE
    let railSubdivSearchSource = new LayerSearchSource({
        layer: railLayer,
        placeholder: 'MBTA',
        searchFields: ['SUBDIV'],
        displayField: 'SUBDIV',
        name: 'Subdiv',
        minSuggestCharacters: 4,
        getSuggestions: (params) =&amp;gt; {
            let query = railLayer.createQuery()
            query.outFields = ['SUBDIV']
            query.returnGeometry = false
            query.returnDistinctValues = true
            query.where = `SUBDIV like '%${params.suggestTerm}%'`
            return railLayer.queryFeatures(query).then((featureSet) =&amp;gt; {                
                let myresult =  featureSet.features.map((feature) =&amp;gt; {
                    return {
                        key: 'name',
                        text: feature.attributes['SUBDIV'],
                        sourceIndex: params.sourceIndex
                    }
                })                
                return myresult
            })
        },
        getResults: (params) =&amp;gt; {
            // ****** if you look in the console you will see it always returns the first item
            console.log(`did you really choose: ${params.suggestResult.text}?`)
        }
    })
    let arcgisCustomSearch = document.getElementById('arcgis-custom-search') 
    arcgisCustomSearch.sources.add(railSubdivSearchSource)

})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Custom Search Issue&amp;lt;/title&amp;gt;
    &amp;lt;link rel="icon" href="data:;base64,=" /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;arcgis-map basemap="gray" center="-100, 34.027" zoom="4"&amp;gt;     
        &amp;lt;arcgis-search id="arcgis-custom-search" include-default-sources-disabled&amp;gt;&amp;lt;/arcgis-search&amp;gt; 
    &amp;lt;/arcgis-map&amp;gt;
    &amp;lt;script type="module" src="/src/main.ts"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also posted the code here as well: &lt;A href="https://github.com/VolpeUSDOT/search-component-question" target="_blank"&gt;https://github.com/VolpeUSDOT/search-component-question&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2025 23:19:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651307#M87627</guid>
      <dc:creator>GaryB</dc:creator>
      <dc:date>2025-09-17T23:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Search component with custom source</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651505#M87628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/427535"&gt;@GaryB&lt;/a&gt;,&amp;nbsp;thanks for posting your question here. Since you're using a layer as the source in the example, it seems like you should use the LayerSearchSource instead of a custom source. Custom source is designed for 3rd party sources.&lt;/P&gt;&lt;P&gt;Here is an example of&amp;nbsp;LayerSearchSource:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/search-component-multisource/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/search-component-multisource/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here is an example of a custom source:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/search-component-customsource/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/search-component-customsource/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And here is an example of using the layer from your app with&amp;nbsp;LayerSearchSource:&amp;nbsp;&lt;A href="https://codepen.io/noash/pen/EaPxjQo?editors=1000" target="_blank"&gt;https://codepen.io/noash/pen/EaPxjQo?editors=1000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Sep 2025 15:40:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651505#M87628</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2025-09-18T15:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Search component with custom source</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651530#M87629</link>
      <description>&lt;P&gt;Thank you for your response&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt;.&amp;nbsp; I should perhaps be more clear on what I'm trying to accomplish.&amp;nbsp; Given a field in a feature layer, after the user types the min suggested characters, I want them to be presented with the list of unique values observed in the data.&amp;nbsp; I think that's pretty clear and is what's already happening in both my example and your example.&amp;nbsp; However, what I really want to do is get back the value that the user selected and do something with it.&amp;nbsp; My example prints the value to the console (but it's always the first value and not the one they selected) whereas your example zooms to the selected elements.&amp;nbsp; Perhaps I'm going about this all wrong.&amp;nbsp; much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Sep 2025 16:26:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651530#M87629</guid>
      <dc:creator>GaryB</dc:creator>
      <dc:date>2025-09-18T16:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Search component with custom source</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651551#M87631</link>
      <description>&lt;P&gt;My apologies&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/427535"&gt;@GaryB&lt;/a&gt;, I misunderstood. Hopefully, if I understand correctly now, what you want is the arcgisSelectResult event:&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-search/#arcgisSelectResult" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-search/#arcgisSelectResult&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This event will fire when the user selects a result from the suggestions. Here is an example that prints the selected suggestion to the browser Console:&lt;BR /&gt;&lt;A href="https://codepen.io/noash/pen/EaPxPRK?editors=1000" target="_blank"&gt;https://codepen.io/noash/pen/EaPxPRK?editors=1000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Sep 2025 17:15:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/search-component-with-custom-source/m-p/1651551#M87631</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2025-09-18T17:15:21Z</dc:date>
    </item>
  </channel>
</rss>

