From 0b1dcbbf5de80f601019f2b114d9f00c9d284f6d Mon Sep 17 00:00:00 2001 From: Chris Lawton <chris.lawton@torchbox.com> Date: Mon, 13 May 2019 10:47:11 +0100 Subject: [PATCH] warn the user of unsaved changes if they try to leave the page whilst editing a comment --- opentech/static_src/src/javascript/apply/edit-comment.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opentech/static_src/src/javascript/apply/edit-comment.js b/opentech/static_src/src/javascript/apply/edit-comment.js index eef32d781..c7245e2e8 100644 --- a/opentech/static_src/src/javascript/apply/edit-comment.js +++ b/opentech/static_src/src/javascript/apply/edit-comment.js @@ -142,4 +142,11 @@ const hideError = () => $(commentError).remove(); + window.addEventListener('beforeunload', (e) => { + if ($(submitEditButton).length) { + e.preventDefault(); + e.returnValue = 'It looks like you\'re still editing a comment. Are you sure you want to leave?'; + } + }); + })(jQuery); -- GitLab