Skip to content

Commit

Permalink
Fix #11900: 14.0.1 FileUpload (advanced): Multiple FileUpload - regre…
Browse files Browse the repository at this point in the history
…ssions when some files do not meet the limits (#11966)
  • Loading branch information
melloware committed May 18, 2024
1 parent 8a70b04 commit 9beed13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,13 @@ if (window.PrimeFaces) {
? {summary: validatorMessageStr, detail: validatorMessageStr}
: ve;

vc.addMessage(element, validatorMsg);
if (Array.isArray(validatorMsg)) {
// e.g. PrimeFaces.validator['primefaces.File'] may return an array of messages
validatorMsg.forEach((msg) => vc.addMessage(element, msg));
}
else {
vc.addMessage(element, validatorMsg);
}

valid = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ if (window.PrimeFaces) {
var filelimit = element.data('p-filelimit'),
allowtypes = element.data('p-allowtypes'),
sizelimit = element.data('p-sizelimit'),
vc = PrimeFaces.validation.ValidationContext;
vc = PrimeFaces.validation.ValidationContext,
messages = [];

var allowtypesRegExp = null;
if (allowtypes) {
Expand All @@ -127,18 +128,22 @@ if (window.PrimeFaces) {
}

if (filelimit && value.length > filelimit) {
throw vc.getMessage(this.FILE_LIMIT_MESSAGE_ID, filelimit);
messages.push(vc.getMessage(this.FILE_LIMIT_MESSAGE_ID, filelimit));
}

for (var file of value) {
if (allowtypesRegExp && (!allowtypesRegExp.test(file.type) && !allowtypesRegExp.test(file.name))) {
throw vc.getMessage(this.ALLOW_TYPES_MESSAGE_ID, file.name, PrimeFaces.utils.formatAllowTypes(allowtypes));
messages.push(vc.getMessage(this.ALLOW_TYPES_MESSAGE_ID, file.name, PrimeFaces.utils.formatAllowTypes(allowtypes)));
}

if (sizelimit && file.size > sizelimit) {
throw vc.getMessage(this.SIZE_LIMIT_MESSAGE_ID, file.name, PrimeFaces.utils.formatBytes(sizelimit));
messages.push(vc.getMessage(this.SIZE_LIMIT_MESSAGE_ID, file.name, PrimeFaces.utils.formatBytes(sizelimit)));
}
}

if (messages.length > 0) {
throw messages;
}
}
},
};
Expand Down

0 comments on commit 9beed13

Please sign in to comment.