Skip to content
Snippets Groups Projects
Commit 8af88f30 authored by Hristo Chonov's avatar Hristo Chonov
Browse files

Issue #3489839 by hchonov: Cannot use forEach on FileList

parent 662b8917
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,6 @@ upload_limit:
js:
js/file-upload-size-limit.js: {}
dependencies:
- core/once
- core/drupal
- core/drupalSettings
- core/once
(function (once) {
(function (Drupal, drupalSettings, once) {
/**
* File upload limit functions.
......@@ -31,13 +31,12 @@
// Check uploaded files if they are exists and singleFileSize is defined.
const $fileInput = event.target;
console.log($fileInput.value)
if ($fileInput.value && $fileInput.files && $fileInput.files.length) {
// Calculate the size of the uploaded files.
var totalUploadSize = 0;
$fileInput.files.forEach(({ size }) => {
for (var i = 0; i < $fileInput.files.length; i++) {
var size = $fileInput.files[i].size;
// Check the single file size limit.
if (size > singleFileSize) {
var error = Drupal.t('The size of the uploaded file (%file_size MB) exceeds the maximum allowed size for a single file of %single_file_max_size MB.', {
......@@ -49,7 +48,7 @@
// Sum the total file upload size.
totalUploadSize += size;
});
}
// Check the total multiple file size limit.
if (multipleLimitType !== 'unlimited' && (totalUploadSize > multipleFileSize)) {
......@@ -114,4 +113,4 @@
},
};
})(once);
})(Drupal, drupalSettings, once);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment