question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option to opt out of Turbo for forms by default and require manual opt in

See original GitHub issue

Anecdotally, one of the biggest deterrents for people upgrading from Turbolinks to Turbo has been the way forms are handled. For Rails users heavily invested in UJS, it’s a mammoth task to rework all the forms to work with Turbo.

I’ve worked around this in the past in Rails by monkey patching form_with to disable Turbo with data-turbo=false; but I think it’d be a great idea to allow a global setting within Turbo to navigate only on forms that have opted in with data-turbo=true.

I’m thinking it could be set at initialization time like: Turbo.start({ forms_opt_out_by_default: true })

I’m happy to spend some time working on this if this is something maintainers would like to support so just opening this issue to get people’s thoughts!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
seanpdoylecommented, Apr 13, 2021

@ayushn21 have you tried setting <html data-turbo="false"> or <body data-turbo="false">, and then incrementally opting into Turbo on an individual <a> and <form> basis?

If it’s <form> elements that are the issue, It might be more straightforward to disable all elements, and then opt back in <a> elements:

addEventListener("turbo:load", () => {
  for (const link of document.querySelectorAll("a")) {
    link.setAttribute("data-turbo", "true")
  }
})
0reactions
ayushn21commented, Apr 14, 2021

Thanks @seanpdoyle. That’s a great stopgap solution on the JS side of things.

I do agree with @leastbad that it’d be great to have a cleaner way to prevent Turbo from navigating on forms by default though. The chat we were having in the StimulusReflex Discord was also centered on what level should this setting be configured (i.e. within Turbo or through a server side helper like config.action_view.form_with_generates_turbo_forms)

If you believe the right way to go about this would be to handle the exclusion of forms on the server rather than within Turbo, I reckon it makes sense to close this issue and we can take the discussion to rails/rails.

Thanks for your input!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigate with Turbo Drive - Hotwire Turbo
Links or forms with Turbo Drive disabled will be handled normally by the browser. If you want Drive to be opt-in rather than...
Read more >
Dynamic forms with Turbo - Thoughtbot
In this case, we need search-params#encode to precede element#click so that the name-value pair is encoded into the [href] attribute before we ...
Read more >
How to Manually Update Smart Cache Version - Egnyte Support
Login with the default username (admin) password (turbocharged). Then multiple options will appear. Choose the upgrade option (No. 10) from those options ......
Read more >
Custom Form Handling With Turbo - Source Diving
Turbo will be a default part of Rails from Rails 7, replacing Turbolinks and ... One option is to use Turbo up to...
Read more >
R Installation and Administration
After downloading manually you need to execute tools/link-recommended from ... The default can be overridden by setting the environment variable R_RD4PDF .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found