简体   繁体   中英

dropzone: submit button doesn't work when no file selected

I have a dropzone form to upload files, included in a standard form with 2 input text, for which the behaviour of the submit button (id=submit-all) is governed by the following javascript part (in order to upload all files once the button is clicked):

Dropzone.options.myDropzone = {
  // Prevents Dropzone from uploading dropped files immediately
  autoProcessQueue: false,
  uploadMultiple: true,
  init: function() {
    var submitButton = document.querySelector("#submit-all")
        myDropzone = this; // closure
    submitButton.addEventListener("click", function() {
      myDropzone.processQueue(); // Tell Dropzone to process all queued files.
    });
    this.on("queuecomplete", function (file) {
      if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
        location.href = 'write.php?final=y';
     }
    });
  }
}; 

When the button is clicked, all files are uploaded and processed as expected, and then the visitor is redirected to the page 'write.php?final=y' (congrats message). However this script does not work when no file is selected: clicking the button has no effect at all.

Could anyone help me with this issue ? Many thanks in advance for your replies !!

queuecomplete is not emitted because there are no files

Dropzone.options.myDropzone = {
  // Prevents Dropzone from uploading dropped files immediately
  autoProcessQueue: false,
  uploadMultiple: true,
  init: function() {
    var submitButton = document.querySelector("#submit-all");
    myDropzone = this; // closure
    submitButton.addEventListener("click", function() {
        if (myDropzone.getUploadingFiles().length === 0 && myDropzone.getQueuedFiles().length === 0) {
            location.href = 'write.php?final=y';
        }
        else {
            myDropzone.processQueue();
        }
    });
  }
};

there is also a way to manually emit event, just simple use

this.emit("signalname");

and the list of events

Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM