javascript - Trigger dropzone cancel event by clicking modal outside -


i work on project uses dropzonejs upload file component. but, faced issue while trying make more customize.

if click somewhere outside of modal window (bootstrap modal), should trigger dropzonejs cancel button event (alert/confirm box, see attached picture). not happen , have never seen related within documents.

enter image description here

any solution?

i have comeover manual , dirty way described below:

i used window.onbeforeunload make thought real , flag. point that, after upload process ended, unbind onbeforeunlad prevent asking "are sure want cancel upload?" if completed.

var cancelconfirmation = "are sure want cancel upload?";  var isfileinprogress = false;  var uploadzone = $("form[class=dropzone]").dropzone({     method: "post",     uploadmultiple: false,     paralleluploads: 1,     dictcanceluploadconfirmation: cancelconfirmation,     success: function (file, response) {         isfileinprogress = false;          window.onbeforeunload = function () { };     },     init: function () {         this.on("error", function (file, response) {             isfileinprogress = false;              window.onbeforeunload = function () { /* unbind */ };         });          this.on("addedfile", function () {             isfileinprogress = true;              window.onbeforeunload = function () {                 return cancelconfirmation;             };         });          this.on("complete", function () {             isfileinprogress = false;              window.onbeforeunload = function () { /* unbind */ };         });          this.on("canceled", function () {             isfileinprogress = false;              window.onbeforeunload = function () { /* unbind */ };         });     } });  $(".modal").on('hide.bs.modal', function (event) {     if (isfileinprogress && !confirm(cancelconfirmation)) {         event.preventdefault();     } }); 

Comments