how to limit dropzone selected files for each time?

118 views Asked by At

I want to limit the number of selectable files when user want to upload with dropzone to maximum of 5 files each time but the user can upload more than that in total. so a user can choose up to 5 files each time, but after selecting the first 5 files, he can choose another 5 files and so on..

so my ideal case is like this:

step 1: user selects and uploads file a1, a2, a3 // success
step 2: user selects and uploads file a11, a12, a13, a14, a15, a16 // these 6 files should not get uploaded

I found getUploadingFiles().length here. but that way, file a11-a16 are still uploaded. if I use removeAll(), then a1-3 will also get deleted. I need it so that only a11-a16 will get cancelled but a1-3 is still safe. can it be done?

my code looks like this:

mydz.on('sendingmultiple', function(file) {
  if (mydz.getUploadingFiles().length > 5) {
    mydz.emit('error', file, 'max selected file is 5!');
  }
});

mydz.on('error', function(file, errMsg, xhr) {
  mydz.removeFile(file);
  $('#form_msg').html(errMsg);
});

EDIT it turns out that when I call getAcceptedFiles().length in the sendingmultiple event will give the number of files selected. so I can use this instead.

0

There are 0 answers