dropzone:未选择文件时提交按钮不起作用

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

我有一个用于上传文件的 dropzone 表单,包含在带有 2 个输入文本的标准表单中,提交按钮 (id=submit-all) 的行为由以下 javascript 部分控制(为了在点击按钮后上传所有文件):

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';
     }
    });
  }
}; 

单击该按钮时,所有文件都按预期上传和处理,然后访问者被重定向到页面 'write.php?final=y'(祝贺消息)。 但是,当没有选择文件时,此脚本不起作用:单击按钮根本没有效果。

谁能帮我解决这个问题? 非常感谢您的回复!!

未发出队列完成,因为没有文件

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();
        }
    });
  }
};

也有手动触发事件的方式,简单使用即可

this.emit("signalname");

和事件列表

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"];