-
Notifications
You must be signed in to change notification settings - Fork 2
#144 confirm if unsaved form changes #169
base: master
Are you sure you want to change the base?
Conversation
root/static/js/unsavedChanges.js
Outdated
(e || window.event).returnValue = ''; | ||
return ''; | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s a trailing newline missing
root/static/js/unsavedChanges.js
Outdated
const inputs = Array.prototype.slice.apply(form.getElementsByTagName('input')); | ||
const textareas = Array.prototype.slice.apply(form.getElementsByTagName('textarea')); | ||
const selects = Array.prototype.slice.apply(form.getElementsByTagName('select')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you align those vertically?
root/static/js/unsavedChanges.js
Outdated
@@ -0,0 +1,21 @@ | |||
const forms = document.getElementsByClassName('confirmIfUnsavedChanges'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "use strict";
?
root/static/js/unsavedChanges.js
Outdated
|
||
window.addEventListener('beforeunload', (e) => { | ||
if (hasUnsavedChanges) { | ||
(e || window.event).returnValue = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a relevant web link from your research, please included it as a comment. I remember the pain of research and even with the correct answer couldn’t find the spec right now.
lib/Coocook/Controller/Recipe.pm
Outdated
@@ -107,6 +107,7 @@ sub edit : GET HEAD Chained('base') PathPart('') Args(0) RequiresCapability('vie | |||
and $c->stash( | |||
import_url => $c->uri_for_action( '/browse/recipe/import', [ $recipe->id, $recipe->url_name ] ) ); | |||
|
|||
push @{ $c->stash->{js} }, '/js/unsavedChanges.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your generic implementation with the <form>
class. Do you think we should simply add this to our global script.js
to utilize it on any page? 🤔
@@ -13,7 +13,7 @@ | |||
</div> | |||
[% END %] | |||
|
|||
<form method="post" action="[% update_url %]"> | |||
<form class="confirmIfUnsavedChanges" method="post" action="[% update_url %]"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out your branch and tested. The JS file was loaded but it had no effect. I made changes and could leave the page without warning.
Issue #144 done