4

I need to add a button that persists the data of the following form but that when pressing it resets the view and stays in it, without redirecting to the index of the controller, I have tried an ajax call but I don't know why it didn't work for me. How can I give a solution and add the button to save and continue?

<%= turbo_frame_tag dom_id(taxonomy) do %>
  <%= form_with(model: [:admin, taxonomy], id: dom_id(taxonomy)) do |form| %>
<div class="box">
  <div class="field is-horizontal">
    <div class="field-body">
      <div class="field">
        <div class="control is-expanded is-relative">
          <%= form.text_field :name, placeholder: true, class: "input mt-5" %>
          <%= form.label :name, class: "label-hidden required" %>
        </div>
      </div>

      <div class="field is-narrow">
        <div class="control mt-5">
          <%= form.submit nil, class: "button is-primary" %>
          <%= link_to "#{ t '.cancel'}", admin_taxonomies_path, class: "button is-light" %>
        </div>
      </div>
    </div>
  </div>
</div>
<% end %>
<% end %>
Joel Blum
  • 7,750
  • 10
  • 41
  • 60
cisco
  • 165
  • 1
  • 8

2 Answers2

9

You need to add a target="_top" attribute to the frame: turbo_frame_tag dom_id(taxonomy), target: :_top Otherwise Turbo tries to replace the current frame containing the form.

Joel Blum
  • 7,750
  • 10
  • 41
  • 60
5

You can also just add data-turbo="false" on your link and the redirection will be working fine.

More info here in the documentation https://turbo.hotwired.dev/handbook/drive#disabling-turbo-drive-on-specific-links-or-forms

olivier dumas
  • 148
  • 2
  • 6