Skip to content

Commit 29aef95

Browse files
committed
feat(forms): add InitFileInputPath function
1 parent f154abd commit 29aef95

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/forms.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,7 @@ export class Forms {
9999

100100
// File Input Path
101101
document.querySelectorAll('.file-field input[type="file"]').forEach((fileInput: HTMLInputElement) => {
102-
fileInput.addEventListener('change', e => {
103-
const fileField = fileInput.closest('.file-field');
104-
const pathInput = <HTMLInputElement>fileField.querySelector('input.file-path');
105-
const files = fileInput.files;
106-
const filenames = [];
107-
for (let i = 0; i < files.length; i++) {
108-
filenames.push(files[i].name);
109-
}
110-
pathInput.value = filenames.join(', ');
111-
pathInput.dispatchEvent(new Event('change'));
112-
});
102+
Forms.InitFileInputPath(fileInput);
113103
});
114104

115105
});
@@ -124,5 +114,19 @@ export class Forms {
124114
textarea.addEventListener('keyup', e => Forms.textareaAutoResize(textarea));
125115
textarea.addEventListener('keydown', e => Forms.textareaAutoResize(textarea));
126116
}
117+
118+
static InitFileInputPath(fileInput: HTMLInputElement){
119+
fileInput.addEventListener('change', e => {
120+
const fileField = fileInput.closest('.file-field');
121+
const pathInput = <HTMLInputElement>fileField.querySelector('input.file-path');
122+
const files = fileInput.files;
123+
const filenames = [];
124+
for (let i = 0; i < files.length; i++) {
125+
filenames.push(files[i].name);
126+
}
127+
pathInput.value = filenames.join(', ');
128+
pathInput.dispatchEvent(new Event('change'));
129+
});
130+
}
127131

128132
}

0 commit comments

Comments
 (0)