diff --git a/app/static/js/upload.js b/app/static/js/upload.js index 3337282..a8927d1 100644 --- a/app/static/js/upload.js +++ b/app/static/js/upload.js @@ -472,7 +472,7 @@ document.addEventListener('DOMContentLoaded', function () { } // File upload functionality - const uploadButton = document.getElementById('upload-button'); + const uploadButton = document.getElementById('select-files-btn'); const uploadModal = document.querySelector('.upload-modal'); // Hide upload modal by default if it exists @@ -482,29 +482,32 @@ document.addEventListener('DOMContentLoaded', function () { uploadModal.style.visibility = 'hidden'; } - // Setup upload button + // Setup upload button with proper existence checks if (uploadButton && fileInput) { - uploadButton.addEventListener('click', function () { + uploadButton.addEventListener('click', function (e) { + e.preventDefault(); // Prevent default button behavior fileInput.click(); }); fileInput.addEventListener('change', function () { - if (this.files.length > 0) { + if (this.files && this.files.length > 0) { // Handle file upload handleFileUpload(this.files); } }); } - // Close upload modal when close button is clicked + // Close upload modal when close button is clicked - with existence check const closeButtons = document.querySelectorAll('.upload-modal .close-btn, .upload-modal .modal-close'); - closeButtons.forEach(btn => { - btn.addEventListener('click', function () { - if (uploadModal) { - uploadModal.classList.remove('active'); - } + if (closeButtons.length > 0) { + closeButtons.forEach(btn => { + btn.addEventListener('click', function () { + if (uploadModal) { + uploadModal.classList.remove('active'); + } + }); }); - }); + } // Handle file upload process function handleFileUpload(files) {