Alert the user if they are leaving unsaved changes in the editor#32
Alert the user if they are leaving unsaved changes in the editor#32halfwit wants to merge 3 commits intowetfish:mainfrom
Conversation
itsrachelfish
left a comment
There was a problem hiding this comment.
Tested locally in both Firefox and Chrome. These changes work insofar as the user is alerted when navigating away from the edit page however I found three problems:
-
A warning message is displayed when saving the page that is being edited. This happens both when you click the save button as well as the preview button. There should not be a warning message when clicking save or preview. This is a major problem and needs to be addressed before this PR can be merged.
-
When the event handler for clicking on a link is triggered and confirmed, the beforeunload logic still fires and displays another warning message. Why is it necessary to have two separate event handlers? Isn't simply using beforeunload enough?
-
The custom confirmation message is not displayed in the beforeunload event handler. This is a minor issue but would be nice to fix while you are working on the other two.
| $(window).on('beforeunload', function(e) { | ||
| if (hasChanges(changed, formData)) { | ||
| var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?'; | ||
| (e || window.event).returnValue = confirmationMessage; | ||
| return confirmationMessage; | ||
| } | ||
| }); |


This creates a confirm dialog on clicking any navigation link while edits are still active.