Reset Dropzone inside a modular window
I have a form inside a bootstrap theme modal block. The form contains several input fields and a Dropzone field, all of which send data to the server via ajax. After filling out the form, I obviously have to reset the form for the next set of inputs. I have successfully reset the form fields, EXCEPT the Dropzone image.
So now when I click the Submit button, after filling out the form, the data is entered. When you click the button to reopen the modal to add a new set, it still displays the previous image. I also need to be away.
I kept looking for a solution on SO and many other places. I couldn't find a solution. Any guidance is appreciated.
HTML:
<form enctype="multipart/form-data" id="addProductImageForm" class="dropzone dz-clickable" action="#">
<div class="dz-default dz-message" ><span>Click here to upload Product Image</span></div>
</form>
JS:
Dropzone.options.addProductImageForm = {
paramName: "productImage",
maxFilesize: 2,
maxFiles: 1,
uploadMultiple: false,
acceptedFiles: "image/*",
dictDefaultMessage: "Click to Upload",
addRemoveLinks: true,
accept: function(file, done) {
if (file.name == "bg.png") {
done("Naha, you don't.");
}
else {
done();
}
},
success: function(d, response, test) {
var value = response.replace("int(0)", "");
var value2 = value.replace(/(\r\n|\n|\r)/gm, "");
$('#product_imageName').val(value2);
},
init: function() {
this.on("maxfilesexceeded", function(file) {
alert("No more files please!");
});
}
};
$("#addProductImageForm").dropzone({url: "/path/to/upload_product_image.php"});
.
.
.
.
var formData = {
(input values here)
};
$.ajax({
type: 'POST',
url: 'path/to/projectsAction.php',
data: formData,
encode: true
})
.done(function(data) {
var value3 = data.replace(/(\r\n|\n|\r)/gm, "");
$('#project_productId').append('<option value="' + value3 + '" selected="selected">' + formData.product_name + '</option>');
$("#addProductForm").find("input[type=text], textarea, select").val("");
$("#addProductImageForm").html("");// THIS IS THE LINE THAT REMOVES THE THUMBNAIL. (From the answer given by xrcwrn)
$('.close').click();
});
event.preventDefault();
+3
source to share