Turbo is a great way to build user interfaces, but most Turbo forms have to wait for the server response. Here’s how I am adding a small loading spi

Adding button loader to Turbo-powered forms

submited by
Style Pass
2025-01-16 09:00:03

Turbo is a great way to build user interfaces, but most Turbo forms have to wait for the server response. Here’s how I am adding a small loading spinner to the submit buttons to improve the UX.

Whenever we submit a Turbo form, we are waiting for a response from the server without any big visual changes. This is especially noticable inside modals and on slow connections.

To improve the situation we’ll create a small Stimulus controller that can be attached to any such form and suggests everything is working despite the wait:

The controller’s only job is to update the button without any interference to the submission process. I find it best when the button’s width doesn’t change, but you can change it to whatever’s needed.

Leave a Comment