Sometimes, we want to do something after all files are uploaded with dropzone.js and JavaScript.
In this article, we’ll look at how to do something after all files are uploaded with dropzone.js and JavaScript.
How to do something after all files are uploaded with dropzone.js and JavaScript?
To do something after all files are uploaded with dropzone.js and JavaScript, we listen for the complete
event.
For instance, we write
Dropzone.options.filedrop = {
init() {
this.on("complete", (file) => {
if (
this.getUploadingFiles().length === 0 &&
this.getQueuedFiles().length === 0
) {
doSomething();
}
});
},
};
to set the Dropzone.options.filedrop.init
property to listen to the complete
event with the 'on'
method.
In the event listener, we get the uploading file’s length and queued file’s length and check if they’re 0.
If they are, then all file uploads are done.
Conclusion
To do something after all files are uploaded with dropzone.js and JavaScript, we listen for the complete
event.