I have this sample:
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!
myDropzone.removeAllFiles()
before upload another file? – Mulligatawny