mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-05-24 10:52:00 +00:00
Validation for input file (#3196)
# Description of Changes Please provide a summary of the changes, including: - Added an invalid event listener for the input element, which will be triggered if the input is empty and the element is required in the form. This is a global change, where all pages using this component will have this functionality. Closes #1841 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [x] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)    ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
parent
d55823ecb1
commit
842581a747
@ -83,6 +83,7 @@ loading=Loading...
|
|||||||
addToDoc=Add to Document
|
addToDoc=Add to Document
|
||||||
reset=Reset
|
reset=Reset
|
||||||
apply=Apply
|
apply=Apply
|
||||||
|
noFileSelected=No file selected. Please upload one.
|
||||||
|
|
||||||
legal.privacy=Privacy Policy
|
legal.privacy=Privacy Policy
|
||||||
legal.terms=Terms and Conditions
|
legal.terms=Terms and Conditions
|
||||||
|
@ -83,6 +83,7 @@ loading=Loading...
|
|||||||
addToDoc=Add to Document
|
addToDoc=Add to Document
|
||||||
reset=Reset
|
reset=Reset
|
||||||
apply=Apply
|
apply=Apply
|
||||||
|
noFileSelected=No file selected. Please upload one.
|
||||||
|
|
||||||
legal.privacy=Privacy Policy
|
legal.privacy=Privacy Policy
|
||||||
legal.terms=Terms and Conditions
|
legal.terms=Terms and Conditions
|
||||||
|
@ -35,6 +35,7 @@ function setupFileInput(chooser) {
|
|||||||
const pdfPrompt = chooser.getAttribute('data-bs-pdf-prompt');
|
const pdfPrompt = chooser.getAttribute('data-bs-pdf-prompt');
|
||||||
const inputContainerId = chooser.getAttribute('data-bs-element-container-id');
|
const inputContainerId = chooser.getAttribute('data-bs-element-container-id');
|
||||||
const showUploads = chooser.getAttribute('data-bs-show-uploads') === "true";
|
const showUploads = chooser.getAttribute('data-bs-show-uploads') === "true";
|
||||||
|
const noFileSelectedPrompt = chooser.getAttribute('data-bs-no-file-selected');
|
||||||
|
|
||||||
let inputContainer = document.getElementById(inputContainerId);
|
let inputContainer = document.getElementById(inputContainerId);
|
||||||
const input = document.getElementById(elementId);
|
const input = document.getElementById(elementId);
|
||||||
@ -58,6 +59,12 @@ function setupFileInput(chooser) {
|
|||||||
inputBtn.click();
|
inputBtn.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle form validation if the input is left empty
|
||||||
|
input.addEventListener("invalid", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
alert(noFileSelectedPrompt);
|
||||||
|
});
|
||||||
|
|
||||||
const dragenterListener = function () {
|
const dragenterListener = function () {
|
||||||
dragCounter++;
|
dragCounter++;
|
||||||
if (!overlay) {
|
if (!overlay) {
|
||||||
|
@ -228,7 +228,7 @@
|
|||||||
loading: '[[#{loading}]]'
|
loading: '[[#{loading}]]'
|
||||||
};</script>
|
};</script>
|
||||||
<div class="custom-file-chooser mb-3"
|
<div class="custom-file-chooser mb-3"
|
||||||
th:attr="data-bs-unique-id=${name}, data-bs-element-id=${name+'-input'}, data-bs-element-container-id=${name+'-input-container'}, data-bs-show-uploads=${showUploads}, data-bs-files-selected=#{filesSelected}, data-bs-pdf-prompt=#{pdfPrompt}">
|
th:attr="data-bs-unique-id=${name}, data-bs-element-id=${name+'-input'}, data-bs-element-container-id=${name+'-input-container'}, data-bs-show-uploads=${showUploads}, data-bs-files-selected=#{filesSelected}, data-bs-pdf-prompt=#{pdfPrompt}, data-bs-no-file-selected=#{noFileSelected}">
|
||||||
<div class="mb-3 d-flex flex-row justify-content-center align-items-center flex-wrap input-container"
|
<div class="mb-3 d-flex flex-row justify-content-center align-items-center flex-wrap input-container"
|
||||||
th:name="${name}+'-input'" th:id="${name}+'-input-container'" th:data-text="#{fileChooser.hoveredDragAndDrop}">
|
th:name="${name}+'-input'" th:id="${name}+'-input-container'" th:data-text="#{fileChooser.hoveredDragAndDrop}">
|
||||||
<label class="file-input-btn d-none">
|
<label class="file-input-btn d-none">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user