innostudio / fileuploader

Beautiful and powerful HTML file uploading tool. A jQuery, PHP and Node.js plugin that transforms the standard input into a revolutionary and fancy field on your page.
141 stars 25 forks source link

`onComplete` also triggers on errors with async upload #23

Closed SimJoSt closed 6 years ago

SimJoSt commented 6 years ago

We use async and automatic upload and wanted to use the onError config option to trigger the validation, if a file isn't properly uploaded. It's important, so the customer realizes, that something is wrong more prominently (css adjustments) and is not able to submit the form. On resolution of these errors (retry/change to correct filesize/...) we want to pass the validation. onComplete seemed perfect for that, unfortunately though, it is triggered on every upload try. It doesn't matter if it's successful or not. Even an unsuccessful retry, will trigger onComplete. I believe it to be caused by our usage of the async and automatic upload.

As the documentation states

Callback fired after all files were uploaded

I expect onComplete only to trigger, if all files have been uploaded successfully.

innostudio commented 6 years ago

@SimJoSt onComplete need to be called for both success/error uploads. We would like to keep the same logic as the jQuery does - http://api.jquery.com/jquery.ajax/.

What you need is to use the API method and in a foreach to check if all files are uploaded or not - item.uploaded == true