Select to view content in your preferred language

How to dynamically change display field for suggestions in search widget?

216
2
08-22-2024 12:59 AM
AMostafaH
Emerging Contributor

I got a problem in search widget which is when searching the displayed field for the suggestions does not match the field matched with search term.

Is there a way to handle it using displayField or suggestionTemplate property?

I'm using version 4.28.

Thanks in advance.

search.jpg

 

0 Kudos
2 Replies
MatthewDriscoll
MVP Alum

Make sure to change includeDefaultSources to false.  I also make sure my sources searchFields, outFields, and diplayField are all the same.

 

const searchWidget = new Search({
      view: theView,
      searchAllEnabled: true,
      maxResults: 10000000,
      maxSuggestions: 10000000,
      title: "Quick Parcel Search",
      label: "Quick Parcel Search",
      includeDefaultSources: false,
      locationEnabled: false,
      exactMatch: false, 
      sources: [
        {
          layer: parcelLayer,
          searchFields: ["PartyName_1"],
          name: "Search by Owner",
          exactMatch: false,
          outFields: ["PartyName_1"],
          displayField: "PartyName_1",         
        },
        {
          layer: parcelLayer,
          searchFields: ["PropertyAddress"],
          name: "Search by Address",
          exactMatch: false,
          outFields: ["PropertyAddress"],
          displayField: "PropertyAddress",
        },
        {
          layer: parcelLayer,
          searchFields: ["QuickRefID"],
          name: "Search by Quick Reference ID",
          exactMatch: false,
          outFields: ["QuickRefID"],
          displayField: "QuickRefID",         
        }
      ],           
    });
0 Kudos
AMostafaH
Emerging Contributor

If I did so, the same layer will appear many times in the suggestions list and I don't want that to happen.

I believe the best way is to use suggestionTemplate property and add all fields used in the searchFields property.

I will attach pictures for your scenario.

Thanks.

1.jpg2.jpg

 

  

 

 

 

  

0 Kudos