I am using the http://www.dropzonejs.com/ (dropzone.js) library. I have initialized one of my form element as,
var drop = $("#upload").dropzone({
uploadMultiple: "true",
addRemoveLinks: "true",
thumbnailWidth: "250",
thumbnailHeight: "250",
maxFilesize: "10",
headers: {
"title": titles,
"location": locations,
"tag": tags
}
});
Now when user clicks on a <button id="close"></button>
button, I want to empty the whole list using the drop.removeAllFiles(true)
function, as suggested on Dropzone.js official website.
So, I tried using
$("#close").click(function(){
drop.removeAllFiles(true);
});
But it's not working, In console.log
I am getting the error removeAllFiles() is not declared for drop
.
Where am I wrong?
To access all files in the dropzone, use myDropzone. files . If you do not need a dropzone anymore, just call . disable() on the object.
Dropzone. js is 'a light weight JavaScript library that turns an HTML element into a "dropzone"'. Users can drag and drop a file onto an area of the page, uploading to a server. If you would like to read more how all of this works skim through the Dropzone.
Set Dropzone autoDiscover to false and initialize dropzone on class="dropzone" . Send AJAX POST request from init function to get all the files list. On successfully callback loop on the response and assign { name: value.name, size: value. size } in mockFile .
jQuery library is optional.
This worked for me.
Dropzone.forElement("#YourDropBoxId").removeAllFiles(true);
Reference: https://github.com/enyo/dropzone/issues/180
Here is the code, it will solve your problem.
$(function() {
Dropzone.options.myAwesomeDropzone = {
init: function () {
var myDropZone = this;
$("#btnRemoveAll").click(function () {
myDropZone.removeAllFiles();
}
);
}
};
});
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