Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the existing file dropzone?

I have this sample:

link

CODE HTML:

<div class="dropzone dz-clickable" id="myDrop">
     <div class="dz-default dz-message" data-dz-message="">
          <span>Upload or drag patient photo here</span>
     </div>
</div>

CODE JS:

 Dropzone.autoDiscover = false;
 var myDropzone = new Dropzone("div#myDrop", {
   addRemoveLinks: true,
   url: "#",
   maxFiles: 1,
   init: function() {

     this.on("maxfilesexceeded", function(file) {
       alert("You are not allowed to chose more than 1 file!");
       this.removeFile(file);

     });

     this.on("addedfile", function(file) {
       myDropzone.options.removefile.call(myDropzone, mockFile);
       //  I want to delete an existing element
     });

   }
 });

 var fileName = $('#profilePicture').val();
 var mockFile = {
   name: fileName,
   size: 12345
 };
 myDropzone.options.addedfile.call(myDropzone, mockFile);
 myDropzone.options.thumbnail.call(myDropzone, mockFile, "https://lh3.googleusercontent.com/-eubcS91wUNg/AAAAAAAAAAI/AAAAAAAAAL0/iE1Hduvbbqc/photo.jpg?sz=104");

What I want to do is when the user uploads a file, then the existing one to be removed.

How can you do this correctly?

Thanks in advance!

like image 537
D.Cristi Avatar asked Mar 08 '16 08:03

D.Cristi


People also ask

How do you destroy dropzone?

Use one of the following methods : The destroy() and disable() methods both exist, and they seem to act the exact same way. In fact, DropZone does not have a real destruction method. These methods will "put the instance in pause" (what is, by design, the closest implementation of a DropZone instance destruction).

What is processQueue dropzone?

processQueue() which checks how many files are currently uploading, and if it's less than options. parallelUploads , . processFile(file) is called. If you set autoProcessQueue to false , then . processQueue() is never called implicitly.

What is dropzone file upload?

Dropzone is a simple JavaScript library that helps you add file drag and drop functionality to your web forms. It is one of the most popular drag and drop library on the web and is used by millions of people.


1 Answers

Try this method.

removedfile: function(file) {
            file.previewElement.remove();
}
like image 149
user8052245 Avatar answered Oct 05 '22 04:10

user8052245