#community-help

Using Search URL with Routing Option and SearchBox Widget

TLDR John was unsure how to handle a search URL with "routing option set to true". Jason suggested using a window.load hook and shared a relevant hook to consider. John then successfully solved the problem using the searchFunction.

Powered by Struct AI
+11
clap1
12
27mo
Solved
Join the chat
Jun 18, 2021 (27 months ago)
John
Photo of md5-7a0ab48aa8979a59e1d8c3919797c1f8
John
12:51 AM
I am using the routing option set to true. Works great. 🙂 But is there a way to know a search was started by loading a "search" url? When I load one it fails to remove some HTML I was removing in the queryHook function of the searchBox widget...
To remove the HTML I was checking wheter the search input field contained some data or not.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:52 AM
Yeah, I've found it strange that the queryHook function doesn't get called on page load. So one way to achieve this is to manually check and sanitize query parameters on window.load...
John
Photo of md5-7a0ab48aa8979a59e1d8c3919797c1f8
John
12:54 AM
So you would create a window.load hook, but what do you mean exactly by "manually check and sanitize query parameters"??
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:57 AM
The same things you're doing inside queryHook to sanitize the input, you'd do on window load
+11
12:58
Jason
12:58 AM
Although if you want to prevent a search from happening at all... I'm not sure how to do that off the top of my head
John
Photo of md5-7a0ab48aa8979a59e1d8c3919797c1f8
John
01:01 AM
OK, thanks!
01:02
Jason
01:02 AM
Looks like this gets triggered on page load as well
John
Photo of md5-7a0ab48aa8979a59e1d8c3919797c1f8
John
01:03 AM
OK, will try out then!
01:12
John
01:12 AM
The searchFunction is the one - it totally works fine with the routing set to true!
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:12 AM
Awesome!
John
Photo of md5-7a0ab48aa8979a59e1d8c3919797c1f8
John
01:12 AM
😁