I'm using jquery fileupload without ui.
I want to control max files uploaded.
For that I'm checking data.files.length in add event and If I select and upload 8 files I get 8 times 1 not once 8
$('#fileupload').fileupload({
   dataType: 'json',
   add: function(e, data) {
      console.log(data.files.length); //8 times 1 - not 8
   }
});
I can make something like this:
add: function(e, data) {
   files+=data.files.length;
   if (files>5) {
      jqXHR = data.submit();
      jqXHR.abort();
   }
},
But often 1 file manages to upload :/
How to limit number of uploaded files without using ui (and all depencies like video, image, audio and so on)?