I noticed that when calling .removeAllFiles() on a dropzone instance that received "mock" files using the technique as shown here does not actually have the desired effect (the mock file is still present).
If you want to remove an added file from the dropzone, you can call . removeFile(file) . This method also triggers the removedfile event.
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 .
Explicitly initialize using dropzone() method and for enabling remove file add addRemoveLinks: true and removefile options. Send AJAX request from the removedfile function where get the file name using the file.name and pass in the AJAX as data. var _ref; return (_ref = file. previewElement) !=
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.
I also had the same problem.
I thinks it happens because the files which are added from the server does not go into the files array and when you call removeAllFiles()
it won't work because it is not in the files array atall.
So the obvious solution would be to add them into the files array,it would look something like this
$(function() {
var mockFile = { name: "banner2.jpg", size: 12345 };
var myDropzone = new Dropzone("#my-awesome-dropzone");
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.files.push(mockFile); // here you add them into the files array
myDropzone.options.thumbnail.call(myDropzone, mockFile,
"http://localhost/test/drop/uploads/banner2.jpg");
});
Now you can use myDropzone.removeAllFiles();
on some event and the files added from server will also get removed from dropzone.
NOTE: Remember when using the above code. if you are firing a server side code to delete the files from server whenever a file is removed from dropzone then all the files that came from the server will get deleted.
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