Ask user for confirmation when they abandon an edit in progress. This fixes #17
This commit is contained in:
parent
d570893a10
commit
6d56ad0001
1 changed files with 11 additions and 2 deletions
|
@ -13,6 +13,13 @@ function queryArgsFromForm(form) {
|
|||
return items.join('&');
|
||||
}
|
||||
|
||||
function isEdited(form) {
|
||||
for (const {name, value, defaultValue} of form.elements) {
|
||||
if (name && (value !== defaultValue)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let hasBeenOpen = false;
|
||||
function openEditor() {
|
||||
const container = document.querySelector(".container");
|
||||
|
@ -91,8 +98,10 @@ function openEditor() {
|
|||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
if (!isEdited(form) || confirm("Discard changes?")) {
|
||||
container.classList.remove('edit');
|
||||
form.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue