Hi I'm using the upload file plugin and I need to validate the number of files added before upload the file...Something like this
$('#fileupload').bind('fileuploadadd', function (e, data) {
filestoupload++;
var numOfDivs = $('.request').size();
if (numOfDivs < filestoupload) {
upload = false; // Is just an example.
}
});
This worked for me, on your fileupload definition add a beforesend, and there do the validation
var maxfiles=3;
$('#fileupload').fileupload(({
url: postFileUrl,
submit: function (event, files) {
//check for max files THIS IS WHERE YOU VALIDATE
//console.log(files.originalFiles.length);
var fileCount = files.originalFiles.length;
if (fileCount > maxFiles) {
alert("The max number of files is "+maxFiles);
throw 'This is not an error. This is just to abort javascript';
return false;
}
}
});
that throw is by far not elegant, if you happend to implement this and find a way to avoid that please make me know (for now is necesary or it will display the error alert for each file uploaded)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With