Merge pull request #7275 from tchak/fix-link-to-with-turbo
Corrige les link_to avec turbo
This commit is contained in:
commit
4c6e50baf4
4 changed files with 43 additions and 7 deletions
|
@ -44,6 +44,10 @@
|
|||
|
||||
// Container for custom turbo-stream actions
|
||||
%turbo-events
|
||||
// Container for turbo form that we can submit from inside other forms
|
||||
|
||||
// We patch `@hotwired/turbo` to attach forms generated from links to this
|
||||
// container instead of the body to avoid conflicts with `@rails/ujs`. We also
|
||||
// patch `@hotwired/turbo` to add a timeout before removing the form because in
|
||||
// order to be accepted as a valid `turbo form`` either global `turbo drive`` should
|
||||
// be enabled or the form needs to have a parent with `data-turbo="true"` on it.
|
||||
%div{ 'data-turbo': 'true' }
|
||||
= form_tag('', id: :turbo_form)
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
= render partial: 'shared/dossiers/editable_champs/repetition_row', locals: { form: form, champ: champ, row: champs }
|
||||
|
||||
.actions{ 'data-turbo': 'true' }
|
||||
= button_tag type: :submit, form: :turbo_form, formaction: champs_repetition_path(champ.id), formmethod: :post, class: 'button add-row' do
|
||||
= link_to champs_repetition_path(champ.id), data: { turbo_method: :post }, class: 'button add-row' do
|
||||
%span.icon.add
|
||||
Ajouter un élément pour « #{champ.libelle} »
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
= render partial: 'shared/dossiers/editable_champs/editable_champ', locals: { form: form, champ: champ }
|
||||
|
||||
.flex.row-reverse{ 'data-turbo': 'true' }
|
||||
= button_tag type: :submit, form: :turbo_form, formaction: champs_repetition_path(champ.id, champ_ids: row.map(&:id), row_id: row_dom_id), formmethod: :delete, class: 'button danger remove-row' do
|
||||
= link_to champs_repetition_path(champ.id, champ_ids: row.map(&:id), row_id: row_dom_id), data: { turbo_method: :delete }, class: 'button danger remove-row' do
|
||||
Supprimer l’élément
|
||||
|
|
32
patches/@hotwired+turbo+7.1.0.patch
Normal file
32
patches/@hotwired+turbo+7.1.0.patch
Normal file
|
@ -0,0 +1,32 @@
|
|||
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||
index 963422f..65364f1 100644
|
||||
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||
@@ -2621,9 +2621,9 @@ class Session {
|
||||
form.addEventListener("turbo:submit-start", () => form.remove());
|
||||
}
|
||||
else {
|
||||
- form.addEventListener("submit", () => form.remove());
|
||||
+ form.addEventListener("submit", () => setTimeout(() => form.remove(), 500));
|
||||
}
|
||||
- document.body.appendChild(form);
|
||||
+ (document.querySelector('body > [data-turbo="true"]') || document.body).appendChild(form);
|
||||
return dispatch("submit", { cancelable: true, target: form });
|
||||
}
|
||||
else {
|
||||
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||
index 101db1f..ce43031 100644
|
||||
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||
@@ -2627,9 +2627,9 @@ Copyright © 2021 Basecamp, LLC
|
||||
form.addEventListener("turbo:submit-start", () => form.remove());
|
||||
}
|
||||
else {
|
||||
- form.addEventListener("submit", () => form.remove());
|
||||
+ form.addEventListener("submit", () => setTimeout(() => form.remove(), 500));
|
||||
}
|
||||
- document.body.appendChild(form);
|
||||
+ (document.querySelector('body > [data-turbo="true"]') || document.body).appendChild(form);
|
||||
return dispatch("submit", { cancelable: true, target: form });
|
||||
}
|
||||
else {
|
Loading…
Reference in a new issue