Using Stimulus to Manage Forms
Turbo is designed to allow regular form submissions to trigger interactive changes on a page without having to reload the entire page. Sometimes, though, you need a little more client-side zest. You might want the form to be submitted on a user action other than clicking a Submit button. Or you might want to gather data from elsewhere on the page. In either case, you can use Stimulus to mediate your form submission.
If you look at the schedule page of our application, it has a search bar that currently does nothing except maybe offer typing practice. What we’d like it to do is return search results on typing. Specifically we want the following functionality:
-
Typing in the box triggers a form submission with search ...
Get Modern Front-End Development for Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.