Faceted Search with Stimulus and Turbo Frames

Harness the power of Stimulus and Turbo Frames to drive a simple but powerful faceted search solution

View Solution on Patreon
Faceted Search with Stimulus and Turbo Frames

Premise

In this challenge we continue where we left off at Challenge 15 - Typeahead Search. We will extend its solution to a more elaborate and generic way to filter our book list.

Starting Point

Let’s start with the server side this time. As in Challenge 15, our “database” containing book records is a static json file that we require in the server’s entrypoint.

There, whenever the /results endpoint is hit with a GET request, we parse the query string into search params.

Then, we consecutively filter the books and return them in the results Turbo frame.

In the markup, we attached the faceted-search Stimulus contoller with /results as the base URL:

https://stackblitz.com/edit/stimulus-frames-faceted-search?file=index.html%3AL43

Whenever an input is being made, the controller’s perform action is triggered:

https://stackblitz.com/edit/stimulus-frames-faceted-search?file=index.html%3AL53

Challenge

Implement this perform action to set the src attribute of the frameTarget to include all query parameters from the formTarget:

Here’s what that should look like:

User clicking through a faceted search form

Teaser

Try a little code golf on this. How succinct can you be?

More from

Stimulus - Video Progress Tracker with LocalStorage
29 October 2024

Store ephemeral user state like video playback progress in localStorage

Stimulus - Image Upload Previews with `URL.createObjectURL`
17 September 2024

Create client-side previews of files using URL.createObjectURL

Stimulus - Removing Markers from a Wavesurfer Element
30 July 2024

Use Stimulus value callbacks to interact with a wavesurfer element and remove markers.

Cookies
essential