- 
                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 ''; | ||
| } | ||
| }) No newline at end of file | 
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
          
        
      | 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? 🤔
| [% 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