Reputation: 165
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 %>
Upvotes: 4
Views: 5109
Reputation: 166
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
Upvotes: 4
Reputation: 7878
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.
Upvotes: 9