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!
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).
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.
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.
Try this method.
removedfile: function(file) {
file.previewElement.remove();
}
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