From 49f1f4e7c76e8154607975d505e995cb9dd15ee6 Mon Sep 17 00:00:00 2001 From: Dimitrios Kaitantzidis Date: Sun, 15 Oct 2023 19:03:10 +0300 Subject: [PATCH] Fixes bug with unfinished filename extension (multiple dots problem) --- .../static/js/multitool/PdfContainer.js | 23 +++++++++++++++++-- src/main/resources/templates/multi-tool.html | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 5ec366ca..907e099a 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -17,6 +17,7 @@ class PdfContainer { this.exportPdf = this.exportPdf.bind(this); this.updateFilename = this.updateFilename.bind(this); this.setDownloadAttribute = this.setDownloadAttribute.bind(this); + this.preventIllegalChars = this.preventIllegalChars.bind(this); this.pdfAdapters = pdfAdapters; @@ -36,6 +37,7 @@ class PdfContainer { const downloadBtn = document.getElementById('export-button'); filenameInput.onkeyup = this.updateFilename; + filenameInput.onkeydown = this.preventIllegalChars; filenameInput.disabled = true; filenameInput.innerText = ""; downloadBtn.disabled = true; @@ -231,7 +233,14 @@ class PdfContainer { let inputArr = filenameInput.value.split('.'); if (inputArr !== null && inputArr !== undefined && inputArr.length > 0) { - filenameInput.value = inputArr[0]; + + inputArr = inputArr.filter(n => n); // remove all empty strings, nulls or undefined + + if (inputArr.length > 1) { + inputArr.pop(); // remove right part after last dot + } + + filenameInput.value = inputArr.join(); this.filename = filenameInput.value; } @@ -275,7 +284,17 @@ class PdfContainer { downloadBtn.disabled = false; this.filename = filenameInput.value; - filenameParagraph.innerText = this.filename + ".pdf"; + } + + preventIllegalChars(e) { + // const filenameInput = document.getElementById('filename-input'); + // + // filenameInput.value = filenameInput.value.replace('.pdf', ''); + // + // // prevent . + // if (filenameInput.value.includes('.')) { + // filenameInput.value.replace('.',''); + // } } } diff --git a/src/main/resources/templates/multi-tool.html b/src/main/resources/templates/multi-tool.html index 4994c078..167d6849 100644 --- a/src/main/resources/templates/multi-tool.html +++ b/src/main/resources/templates/multi-tool.html @@ -23,7 +23,7 @@
- +