Only enable save button when content is not empty

This commit is contained in:
Lukas Schulte Pelkum 2022-01-30 15:12:34 +01:00
parent e8e2b49466
commit 7a8d8e1573
No known key found for this signature in database
GPG Key ID: 408DA7CA81DB885C
2 changed files with 8 additions and 3 deletions

View File

@ -92,7 +92,7 @@ export async function initialize() {
ENCRYPTION_IV = json.metadata.pf_encryption.iv;
} catch (error) {
console.log(error);
Notifications.error("Could not decrrypt paste; make sure the decryption key is correct.");
Notifications.error("Could not decrypt paste; make sure the decryption key is correct.");
setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000);
return;
}
@ -112,6 +112,12 @@ export async function initialize() {
INPUT_ELEMENT.addEventListener("input", () => {
updateLineNumbers(INPUT_ELEMENT.value);
if (BUTTON_SAVE_ELEMENT.hasAttribute("disabled") && INPUT_ELEMENT.value.length > 0) {
BUTTON_SAVE_ELEMENT.removeAttribute("disabled");
}
if (!BUTTON_SAVE_ELEMENT.hasAttribute("disabled") && INPUT_ELEMENT.value.length == 0) {
BUTTON_SAVE_ELEMENT.setAttribute("disabled", true);
}
});
}
@ -160,7 +166,6 @@ function updateButtonState() {
BUTTON_REPORT_ELEMENT.classList.remove("hidden");
}
} else {
BUTTON_SAVE_ELEMENT.removeAttribute("disabled");
BUTTON_EDIT_ELEMENT.setAttribute("disabled", true);
BUTTON_DELETE_ELEMENT.setAttribute("disabled", true);
BUTTON_COPY_ELEMENT.setAttribute("disabled", true);

View File

@ -35,7 +35,7 @@
<line x1="12" y1="9" x2="12" y2="15" />
</svg>
</button>
<button class="button" id="btn_save" title="Save paste (Ctrl + S)">
<button class="button" id="btn_save" title="Save paste (Ctrl + S)" disabled>
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-floppy" width="40"
height="40" viewBox="0 0 24 24" stroke-width="1.5" stroke="#bebebe" fill="none"
stroke-linecap="round" stroke-linejoin="round">