2020-06-16 08:09:00 -04:00
|
|
|
export default function initFilePickers() {
|
|
|
|
const filePickers = document.querySelectorAll('.js-filepicker');
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
filePickers.forEach((filePicker) => {
|
2020-06-16 08:09:00 -04:00
|
|
|
const button = filePicker.querySelector('.js-filepicker-button');
|
|
|
|
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
const form = button.closest('form');
|
|
|
|
form.querySelector('.js-filepicker-input').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
const input = filePicker.querySelector('.js-filepicker-input');
|
|
|
|
|
|
|
|
input.addEventListener('change', () => {
|
|
|
|
const form = input.closest('form');
|
|
|
|
const filename = input.value.replace(/^.*[\\\/]/, ''); // eslint-disable-line no-useless-escape
|
|
|
|
|
|
|
|
form.querySelector('.js-filepicker-filename').textContent = filename;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|