How to disable clickable the form with Dropzone.js?

后端 未结 10 937
孤城傲影
孤城傲影 2020-12-29 08:39

I\'m using Dropzone.js to upload files to the server. I setting up my Dropzone maxFiles parameter to 10 and I was tried this:

$(\'.         


        
相关标签:
10条回答
  • 2020-12-29 08:58

    If clickable option is set to true, the dropzone element itself will be clickable, if false nothing will be clickable.

    You can also pass an HTML element, a CSS selector (for multiple elements) or an array of those. In that case, all of those elements will trigger an upload when clicked.

    var myDropzone = new Dropzone("div.dropzone", { url: "/file/post", clickable: false });
    
    0 讨论(0)
  • 2020-12-29 08:59
    myDropzone.on('maxfilesreached', function() {
        myDropzone.removeEventListeners();
    });
    myDropzone.on('removedfile', function (file) {
        myDropzone.setupEventListeners();
    });
    

    Don't forget init _updateMaxFilesReachedClass if you have files from your server.

    myDropzone._updateMaxFilesReachedClass()
    
    0 讨论(0)
  • 2020-12-29 09:01

    Here we go, updated based on comments below.

    How to disable the dropzone "click to open file dialog box" event when maxFiles is reached:

    $('.dropzone').dropzone({
        maxFiles: 10,
        init: function() {
            this.on('maxfilesreached', function() {
                $('.dropzone').removeClass('dz-clickable'); // remove cursor
                $('.dropzone')[0].removeEventListener('click', this.listeners[1].events.click);
            });
        }
    

    I don't know how reliable the "1" in this.listeners[1] is, but that's where the click event function lives in my current dropzone configuration.

    0 讨论(0)
  • 2020-12-29 09:05

    This works PERFECTLY!!! and works on 4.0.1

    //disable the click of your clickable area
    $(".dz-hidden-input").prop("disabled",true);
    
    //enalbe the click of your clickable area
    $(".dz-hidden-input").prop("disabled",false);
    
    0 讨论(0)
提交回复
热议问题