I have a JSF application with Primefaces 5.1.
<p:fileUpload id="file-upload-input1" label="#{msg['fileUpload.attachment']}" auto="true"
fileUploadListener="#{fileUploadController.uploadFile}"
widgetVar="fileUploadWidget"
mode="advanced"
onstart="PF('loadingDialog').show();"
fileLimit="30"
oncomplete="onCompleteAllFiles(this);"
onerror="alert('Error. Try again')"
invalidFileMessage="#{msg['fileUpload.file.invalid.type']}"
invalidSizeMessage="#{msg['fileUpload.file.invalid.size']}"
sizeLimit="3221223823"
multiple="true"
allowTypes="/(\.|\/)(xml|pdf)$/" update="file-upload-info"/>
It seems that the fileLimit parameter doesn't cancel the whole file upload. It just cancels upload for the files exceeding the limit. I want to disable uploading the whole bulk and inform user that there is a limit and he should try again with correct amount of files.
I've tried with a solution suggested by
https://stackoverflow.com/a/47473958
to validate the form before submitting, but I'm not able to obtain amount of files:
var fnRef = function (event) {
console.log("Button clicked");
if (triggerValidation) {
//prevent file browser to open
event.preventDefault();
//trigger validation via p:remoteCommand;
submitSelection();
} else {
//File browser will be opened at this point
}
};
How can I cancel the WHOLE upload, when fileLimit validation fails?