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()" > - + - +
- + -