Hi All,
The code would normally work using Javascript 4.3, my search widget outside my mapView but seems not to be working in 4.4.
Thanks in advance
Solved! Go to Solution.
Hi Henry obaseki,
If you want to use your own form and input with the searchWidget, you have to use the "search" method of the widget.
In this case you don't need to add the widget in a container, but simply construct it with the view. You can then use the input value to search with the widget.
Your code will look like that :
var searchWidget = new Search{view: view1})
function mySubmitFunction () {
let element = document.getElementById("YourInputID")
let address = element.value
searchWidget.search(address).then((results) => {
console.log("Search widget results :", results)
})
})
I made a plunker to show an example with plainJS here: Plunker.
It will show the result on the map, only if you get a single result, otherwise you will need to pick up the suggested results and pass them on to the view so that the end user can select the correct result.
Hope it help!
Best
Hi Henry obaseki,
If you want to use your own form and input with the searchWidget, you have to use the "search" method of the widget.
In this case you don't need to add the widget in a container, but simply construct it with the view. You can then use the input value to search with the widget.
Your code will look like that :
var searchWidget = new Search{view: view1})
function mySubmitFunction () {
let element = document.getElementById("YourInputID")
let address = element.value
searchWidget.search(address).then((results) => {
console.log("Search widget results :", results)
})
})
I made a plunker to show an example with plainJS here: Plunker.
It will show the result on the map, only if you get a single result, otherwise you will need to pick up the suggested results and pass them on to the view so that the end user can select the correct result.
Hope it help!
Best
Thanks Jean,
Tried the code it works!
Thank you
Hi Jean-Marc Roy,
One more thing
Do have multiple search sources to pass to my widget, it does work on a different html, its just how to incorporate it to my above code if you could please test in using the Plunker
Thank you!
Hi Henry obaseki,
Here is a working example with your layer sources: Plunker.
I was able to find a location on layerSource1 with "CM" and find a location on layerSource2 with "IG11".
Thank you, its working...
Is it possible to have the search widget auto-fill when it's outside of the map?