Skip to content

Instantly share code, notes, and snippets.

@fsuuaas
Last active September 1, 2018 13:44
Show Gist options
  • Save fsuuaas/b1e07b1b2e005876e9970aedac99fb6a to your computer and use it in GitHub Desktop.
Save fsuuaas/b1e07b1b2e005876e9970aedac99fb6a to your computer and use it in GitHub Desktop.
<label for="reference">Snapshot <span>*</span></label>
<div class="dropzone" id="myDropzone"></div>
<script>
Dropzone.autoDiscover = false;
modal = $("#successModal");
form = $("#imageUploadForm");
Dropzone.options.myDropzone= {
url: '/user/request-feature-save',
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 5,
maxFilesize: 1,
acceptedFiles: 'image/*',
addRemoveLinks: true,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
reset: function () {
console.log("resetFiles");
this.removeAllFiles(true);
},
init: function() {
dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
// for Dropzone to process the queue (instead of default form behavior):
document.getElementById("submit-all").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
//send all the form data along with the files:
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("title", jQuery("#title").val());
formData.append("description", jQuery("#description").val());
formData.append("reference", jQuery("#reference").val());
});
this.on("success", function () {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
$('#successModal').modal();
setTimeout(function () {
$('#successModal').modal('hide');}, 8000);
}
$("#successModal").on("hidden.bs.modal", function () {
// form[0].reset();
// dzClosure.removeAllFiles(true);
// $("#myDropzone>.dz-message").show();
// document.getElementById('ifYes').style.display = 'none';
// document.getElementById('myDropzone').classList.remove("dropzone");
// dzClosure.destroy();
location.reload();
});
});
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment