如何覆盖Dropzone.js中的确认对话框?

时间:2017-03-24 10:29:08

标签: dropzone.js

我正在尝试在我的项目上实现dropzone。我创建了一个自定义确认对话框,我在项目的每个部分都使用过它。我想在dropzone上使用相同的自定义确认对话框。我该怎么办?

const initDropzone = (obj) => {
const newobj = obj;
console.log(newobj);
console.log(newobj.options);
newobj.confirm = function (question, accepted, rejected) {
  console.log('asking question');
  mscConfirm({
    title: 'Management Console',
    subtitle: question,
    dismissOverlay: true,
    onOk() {
      accepted();
    },
  });
};
return newobj;
}

2 个答案:

答案 0 :(得分:1)

这对我有用...我添加了这段代码:

$("div#resource_upload_{{ $lecture->id }}").dropzone({ 

    // here go your other dropzone options

    // this option stops the files form auto-uploading
    autoProcessQueue: false,

    // here we add the question
    init: function (){

    // get the dropzone object
    myDropzone = this;

    // overwrite the addedfile function 
    myDropzone.on("addedfile", function(event) {

        // this is my confirm function, you can insert your
        var r = confirm("Press a button!");

        if (r == true) {
            txt = "You pressed OK!";
            // this starts the upload proces....
            myDropzone.processQueue();
        } else {
            // ...or not
            txt = "You pressed Cancel!";
        }
    });
});

因此,autoProcessQueue会停止上传文件,然后覆盖“addedfile”函数,并在其中随意执行。 myDropzone.processQueue()继续文件上传。

希望这有帮助。

答案 1 :(得分:0)

您可以覆盖默认确认。

Dropzone.confirm = function(question, accepted, rejected) {

    showConfirm(question);


    $(document).on('click', '#accept-confirm', function() {
        hideConfirm();
        accepted();
    });

}

我正试图弄清楚如何处理已接受的& amp;拒绝了自己,因为我的方式只允许我删除一个上传的文件。在第一个之后我得到一个错误

  

未捕获的TypeError:无法读取属性' removeChild'为null

它位于http://www.dropzonejs.com/#dropzone-methods下的文档中,但关于它的信息不多。

相关问题