In JavaScript 4.10, the second Search Widgets changes the properties on the main one

456
6
Jump to solution
01-03-2019 10:36 AM
DanielWebb
Occasional Contributor

I switching to JavaScript 4.10, the Search widget acts funny.  I have two Search widgets in my app and when the second is activated it changes the properties on the main one.

Since this is the newest api, presumably this is a bug.  When I switch to 4.8 or 4.9 it works fine.

I attached some screenshots showing what I'm talking about.  The placeholder for the first widgets changes when the second is created.

1 Solution

Accepted Solutions
MattDriscoll
Esri Contributor

Hi Daniel,

Thanks for bringing this to our attention. This is a bug with the Search widget sharing the same sources. In order to fix this, can you add the following line after you create your search widgets?

searchWidget.viewModel._set("allSources", searchWidget.viewModel.allSources.clone());

This will make a clone of the `allSources` collection which will allow you to modify it without affecting the other search widget. Feel free to add this one liner to the other widget as well.

We'll get this fixed for 4.11. 

Thanks!

View solution in original post

0 Kudos
6 Replies
MattDriscoll
Esri Contributor

Hi Daniel,

Thanks for bringing this to our attention. This is a bug with the Search widget sharing the same sources. In order to fix this, can you add the following line after you create your search widgets?

searchWidget.viewModel._set("allSources", searchWidget.viewModel.allSources.clone());

This will make a clone of the `allSources` collection which will allow you to modify it without affecting the other search widget. Feel free to add this one liner to the other widget as well.

We'll get this fixed for 4.11. 

Thanks!

0 Kudos
MattDriscoll
Esri Contributor

Here is a codepen too: A Pen by Matt Driscoll 

MikkLauringson
New Contributor II

If a source has resultSymbol, then it causes an error.

ERROR TypeError: "this.resultSymbol.clone is not a function"

clone /4.10/esri/widgets/Search.js:135:396

0 Kudos
MattDriscoll
Esri Contributor

Hey Mikk, can you make sure that the resultSymbol is an instance of a symbol and not an object? What symbol type is it?

MikkLauringson
New Contributor II

Yes, it was an object. It works with instance. Also other solution was to set it after cloning.

resultSymbol: {type: 'picture-marker', ...}

Thank you!

0 Kudos
DanielWebb
Occasional Contributor

Thank you, Matt!  That seems to work.

0 Kudos