In Rails 7, Turbolinks is replaced by Hotwire / Turbo. This patches up web links so that they become AJAX-style requests just like Turbolinks did, but also patches up forms. On the whole, we found this broke swathes of our application.
flash
and render :new
/render :edit
" - break, astonishingly; one must add status: :unprocessable_entity
and cross fingers....#foo
), Turbo strips it.In the end, there's only so much data: {turbo: false}
it makes sense to scatter all over your code base. Worse, we're using SimpleForm, so this becomes the even-more-cumbersome html: {data: {turbo: false}}
.
Is there a way to _globally disable Turbo just for forms (ideally all forms, whatever their origin - just leave the <form>
tag and everything inside it completely alone please) but leave the rest of its behaviour unchanged?
Wish granted, although, undocumented. Available since turbo v7.2.0 (turbo-rails v1.3.0).
// app/javascript/application.js
Turbo.setFormMode("on" | "off" | "optin")
// for turbo v8.0.6+
Turbo.config.forms.mode = "on" | "off" | "optin"
"on"
- default - Turbo forms all the time. Use data-turbo="false"
to disable turbo on individual forms.
"off"
- No turbo forms ever. data-turbo="true"
is ignored.
"optin"
- No turbo forms unless you insist. Use data-turbo="true"
to enable turbo on individual forms.