mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Revert "Prevent frame navigations when form is changed"
It was too hacky and had issues. Let's just disable Turbo for those links for now.
This reverts commit 1d1169b478.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
- content_for :page_title do
|
||||
= t('.header.title')
|
||||
- content_for :page_actions do
|
||||
%div{ :class => "toolbar", 'data-turbo': true }
|
||||
%div{ :class => "toolbar" }
|
||||
%ul{ :class => "actions header-action-links inline-menu" }
|
||||
%li#new_product_link
|
||||
= button_link_to t(:new_product), "/admin/products/new", { :icon => 'icon-plus', :id => 'admin_new_product' }
|
||||
|
||||
@@ -33,25 +33,12 @@ export default class BulkFormController extends Controller {
|
||||
|
||||
this.form.addEventListener("submit", this.#registerSubmit.bind(this));
|
||||
window.addEventListener("beforeunload", this.preventLeavingChangedForm.bind(this));
|
||||
document.addEventListener("turbo:before-visit", this.preventLeavingChangedForm.bind(this));
|
||||
|
||||
// Frustratingly there's no before-frame-visit, and no other events work, so we need to bind to
|
||||
// the frame and listen for any link clicks (maybe other things too).
|
||||
this.turboFrame = this.form.closest("turbo-frame");
|
||||
if(this.turboFrame){
|
||||
this.turboFrame.addEventListener("click", this.preventLeavingChangedForm.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
// Make sure to clean up anything that happened outside
|
||||
this.#disableOtherElements(false);
|
||||
window.removeEventListener("beforeunload", this.preventLeavingChangedForm.bind(this));
|
||||
document.removeEventListener("turbo:before-visit", this.preventLeavingChangedForm.bind(this));
|
||||
|
||||
if(this.turboFrame){
|
||||
this.turboFrame.removeEventListener("click", this.preventLeavingChangedForm.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
// Register any new elements (may be called by another controller after dynamically adding fields)
|
||||
@@ -92,21 +79,9 @@ export default class BulkFormController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// If navigating away from form, warn to prevent accidental data loss
|
||||
// If form is not being submitted, warn to prevent accidental data loss
|
||||
preventLeavingChangedForm(event) {
|
||||
const target = event.target;
|
||||
// Ignore non-navigation events (see above)
|
||||
if(this.turboFrame && this.turboFrame.contains(target) && (target.tagName != "A" || target.dataset.turboFrame != "_self")){
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.formChanged && !this.submitting) {
|
||||
// If fired by a custom event (eg Turbo), we need to explicitly ask.
|
||||
// This is skipped on beforeunload.
|
||||
if(confirm(I18n.t("are_you_sure"))){
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel the event
|
||||
event.preventDefault();
|
||||
// Chrome requires returnValue to be set, but ignores the value. Other browsers may display
|
||||
|
||||
Reference in New Issue
Block a user