Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call the .removeAllFiles() function in Dropzone.js after a click on a button

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?

like image 399
rishy Avatar asked Aug 27 '13 08:08

rishy


People also ask

How do I retrieve files from dropzone?

To access all files in the dropzone, use myDropzone. files . If you do not need a dropzone anymore, just call . disable() on the object.

How does dropzone JS work?

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.

How can I show you the files already stored on server using dropzone JS?

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 .

Does dropzone require jQuery?

jQuery library is optional.


2 Answers

This worked for me.

Dropzone.forElement("#YourDropBoxId").removeAllFiles(true);

Reference: https://github.com/enyo/dropzone/issues/180

like image 79
Ducain Avatar answered Sep 28 '22 05:09

Ducain


Here is the code, it will solve your problem.

$(function() {
            Dropzone.options.myAwesomeDropzone = { 
            init: function () {
                var myDropZone = this;
                $("#btnRemoveAll").click(function () {
                            myDropZone.removeAllFiles();
                        }
                );
            }

        };
 });
like image 34
Dilip Kumar Avatar answered Sep 28 '22 05:09

Dilip Kumar