From 9beed13570aff94898db5c6e1ef6b62df1bc66a4 Mon Sep 17 00:00:00 2001 From: Melloware Date: Sat, 18 May 2024 12:32:04 -0400 Subject: [PATCH] Fix #11900: 14.0.1 FileUpload (advanced): Multiple FileUpload - regressions when some files do not meet the limits (#11966) --- .../primefaces/validation/validation.common.js | 8 +++++++- .../primefaces/validation/validation.validators.js | 13 +++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.common.js b/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.common.js index c8ea70a256..c82e7cb1e5 100644 --- a/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.common.js +++ b/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.common.js @@ -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; } diff --git a/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.validators.js b/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.validators.js index c651ea1337..0dee66c105 100644 --- a/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.validators.js +++ b/primefaces/src/main/resources/META-INF/resources/primefaces/validation/validation.validators.js @@ -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) { @@ -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; + } } }, };