summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/file_pickers.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/file_pickers.js')
-rw-r--r--app/assets/javascripts/file_pickers.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/assets/javascripts/file_pickers.js b/app/assets/javascripts/file_pickers.js
new file mode 100644
index 00000000000..956a4954afb
--- /dev/null
+++ b/app/assets/javascripts/file_pickers.js
@@ -0,0 +1,21 @@
+export default function initFilePickers() {
+ const filePickers = document.querySelectorAll('.js-filepicker');
+
+ filePickers.forEach(filePicker => {
+ 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;
+ });
+ });
+}