Improving Search Functionalities

We'll now learn about how to improve search functionalities in the application by adding JavaScript actions.

Adding JavaScript Actions to Search

Our search bar works, but we can still improve it a bit. It would be nice if the modal was reset when we delete all the characters in the search bar, as well as when we click outside the window. However, the latter might be tricky. To get the “outside the window” part to work, by definition, we need to capture click events outside the scope of our Stimulus controller. Luckily, Stimulus has a way to do that.

First, we need to add an action to our search results object:

Get hands-on with 1000+ tech skills courses.