8

In Rails 7 a form generated with form_with tag sends remote request by default (turbo.js handles form submit event instead, whatever).

Previously one would pass remote: false or local: true parameters to form helper, to get just a regular HTML form behavior.

But not anymore, this doesn't work:

<%= form_with scope: :session, url: session_path, local: true do |form| %>
  <p><%= form.label :email %></p>
  <p><%= form.text_field :email %></p>

  <p class="mt"><%= form.label :password %></p>
  <p><%= form.password_field :password %></p>

  <p class="mt"><%= form.submit "Enter" %></p>
<% end %>

What option should I pass to form_with helper in order to get a non-XHR request from my form?

installero
  • 9,096
  • 3
  • 39
  • 43

1 Answers1

9

You actualy need to pass a data: {turbo: false} to make form send a regular request:

<%= form_with scope: :session, url: session_path, data: {turbo: false} do |form| %>
  <p><%= form.label :email %></p>
  <p><%= form.text_field :email %></p>

  <p class="mt"><%= form.label :password %></p>
  <p><%= form.password_field :password %></p>

  <p class="mt"><%= form.submit "Enter" %></p>
<% end %>
installero
  • 9,096
  • 3
  • 39
  • 43
  • 1
    I wouldn't be suprised if this is or will become a "first- class" option (Like with Rails UJS) so you can just write `form_with ..., turbo: false` instead of explicitly setting it as a data attribute. – max Feb 20 '22 at 13:58
  • Agreed! For now on (rails 7.0.1) you can't use it like this. I've checked it twice. – installero Feb 20 '22 at 16:37