1
0
Fork 0
nyazoom/dist/scripts/file_label.js

19 lines
608 B
JavaScript
Raw Normal View History

2023-07-26 08:53:41 +00:00
document.addEventListener("DOMContentLoaded", () => {
let inputs = document.querySelectorAll('input#file');
Array.prototype.forEach.call(inputs, function(input) {
let label = input.nextElementSibling;
let labelVal = label.innerHTML;
input.addEventListener('change', function(e) {
let fileName = '';
if (this.files?.length > 1) {
fileName = this.getAttribute('data-multiple-caption')?.replace('{count}', this.files.length);
} else {
fileName = e.target.value.split('\\').pop();
}
label.innerHTML = fileName || labelVal;
});
});
}, false);