From 98636bace53ee40090879c69e79e4e94b3c92489 Mon Sep 17 00:00:00 2001 From: Rostislav Raykov Date: Mon, 2 Dec 2024 13:49:33 +0200 Subject: [PATCH] added a warning if keep indefinitely is checked and a password is not input --- src/main/resources/static/js/upload.js | 15 ++++++ src/main/resources/templates/upload.html | 63 +++++------------------- 2 files changed, 28 insertions(+), 50 deletions(-) diff --git a/src/main/resources/static/js/upload.js b/src/main/resources/static/js/upload.js index 7d8b793..906b8b9 100644 --- a/src/main/resources/static/js/upload.js +++ b/src/main/resources/static/js/upload.js @@ -69,6 +69,21 @@ function isPasswordProtected() { return passwordField && passwordField.value.trim() !== ""; } +function validateKeepIndefinitely() { + const keepIndefinitely = document.getElementById("keepIndefinitely").checked; + const password = document.getElementById("password").value; + + if (keepIndefinitely && !password) { + return confirm( + "You have selected 'Keep indefinitely' but haven't set a password. " + + "This means the file will only be deletable by an admin. " + + "Do you want to proceed?" + ); + } + + return true; // Allow form submission if conditions are not met +} + function validateFileSize() { const maxFileSize = document.getElementsByClassName('maxFileSize')[0].innerText; const file = document.getElementById('file').files[0]; diff --git a/src/main/resources/templates/upload.html b/src/main/resources/templates/upload.html index 58101e5..7e41ec6 100644 --- a/src/main/resources/templates/upload.html +++ b/src/main/resources/templates/upload.html @@ -85,23 +85,17 @@ id="uploadForm" method="post" th:action="@{/file/upload}" + onsubmit="return validateKeepIndefinitely()" > - + - +
- + -