A common pattern is having a search form that filters a list of items. That's what we're going to build now with a minimal amount of code using Turbo Frames and Stimulus. Here's what it will look like in the end. We've got a bunch of jobs, each with...
code.avi.nyc6 min readHey there, Avi; thank you for sharing this post!
I was trying it on my machine, and as it turns out, we don't even need to create a custom stimulus controller.
All you need to do is set the form's data-turbo-frame="jobs" attribute and, instead of using the TurboVisit + FormData combo, call the form's requestSubmit() function.
<form data-turbo-frame="jobs" etc>
<%= select_tag :category, etc, onchange: "this.form.requestSubmit()" %>
</form>
More info:
Let me know what you think, cheers!
Stefanos N.
Hi Avi, thanks a lot for this, it's super helpful and extremely fast.
Another question I would have is how would you handle counters for these filters? Let's say we have counters next to each filter and on each filter selection, should update all the other filter counters