Search Widget possible to cancel or abort a search?

670
2
Jump to solution
11-03-2022 10:47 AM
BryanMc
Frequent Contributor

Wondering if it's possible to cancel a search within the search widget (ArcGIS JavaScript API 4.24) based on the text in the search widget text area before it is sent to an online source?

I'm able to trap the search when it starts, but there isn't an event to cancel/abort from yet. I don't want to use the 'search-complete' event since it's already too late at that point. 

 

searchWidget.on("search-start", function (event) {
    if (searchWidget.searchTerm == "my search term") {
        //Cancel the search
    }
});

 

The goal is to interrogate the search string for a specific value and cancel the search to perform a different action.  TLDR: Would like to listen for a local coordinate input x,y using a regex. If matches the pattern, don't send a search, just pan/zoom the map (since map is in a local coordinate system as well). I've also looked at reactiveUltils, but can't seem to figure out how to cancel the search.

0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

One option would be to use RequestInterceptor to inspect the search and modify it before sending it to the geocoding service (or doing something else entirely).

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#request

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#RequestInterceptor

 

 

View solution in original post

0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor

One option would be to use RequestInterceptor to inspect the search and modify it before sending it to the geocoding service (or doing something else entirely).

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#request

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#RequestInterceptor

 

 

0 Kudos
BryanMc
Frequent Contributor

Thank you Noah! This doesn't cancel the search but it does allow me intercept and do whatever I want. Just need to craft my own return object once done to finish the bypass process. 

If I return back my own random object, the Search Widget will say "No Results". But if I return my own custom search result object it can pan/zoom and still look like a completed search. In 3x we could cancel the request and take over - so without that option in 4x, this is definitely the way to go.

0 Kudos