This commit is contained in:
Ross
2025-12-05 13:36:18 +00:00
parent bb8298b18c
commit e5fa66d622
+12
View File
@@ -114,6 +114,18 @@
if(!label) return; if(!label) return;
if(fi.files.length === 0) label.textContent = 'No file chosen'; if(fi.files.length === 0) label.textContent = 'No file chosen';
else label.textContent = fi.files.length > 1 ? fi.files.length + ' files selected' : fi.files[0].name; else label.textContent = fi.files.length > 1 ? fi.files.length + ' files selected' : fi.files[0].name;
// Prefill the name input from the filename if the name is empty
try {
const nameInput = formRoot.querySelector('input[name="name"]');
if(nameInput && (!nameInput.value || nameInput.value.trim() === '')){
const f = fi.files && fi.files[0];
if(f && f.name){
const base = f.name.replace(/\.[^/.]+$/, '');
const title = base.replace(/[_-]+/g, ' ').split(/\s+/).map(function(w){ return w.length? (w.charAt(0).toUpperCase() + w.slice(1)) : ''; }).join(' ').trim();
if(title) nameInput.value = title;
}
}
} catch(e){ /* ignore */ }
}); });
// Make sure clicking the visual label triggers the input if not already clickable // Make sure clicking the visual label triggers the input if not already clickable
const outerLabel = fi.closest('.file').querySelector('.file-label'); const outerLabel = fi.closest('.file').querySelector('.file-label');