How to disable clickable the form with Dropzone.js?

后端 未结 10 936
孤城傲影
孤城傲影 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:46

    The easiest way is: myDropzone.disable();

    0 讨论(0)
  • 2020-12-29 08:47

    Why do not you just use CSS to disable the click event. When max files is reached, Dropzone will automatically add a class of dz-max-files-reached.

    Use css to disable click on dropzone:

    .dz-max-files-reached {
      pointer-events: none;
      cursor: default;
    }
    
    0 讨论(0)
  • 2020-12-29 08:47

    This is how I achieved this:

    $('.dz-message').html('<span class="text-center"><span class="font-lg visible-xs-block visible-sm-block visible-lg-block"><span class="font-lg"><i class="fa fa-caret-right text-danger"></i><i>Maximum uploads have been reached</i></span></span></span>');
    $('.dropzone').removeClass('dz-clickable');
    $('.dropzone')[0].removeEventListener('click', myDropzone.listeners[1].events.click);
    $('.dropzone')[0].removeEventListener('drop', myDropzone.listeners[0].events.drop);
    $('.dropzone')[0].removeEventListener('dragstart', myDropzone.listeners[0].events.dragstart);
    $('.dropzone')[0].removeEventListener('dragenter', myDropzone.listeners[0].events.dragenter);
    $('.dropzone')[0].removeEventListener('dragover', myDropzone.listeners[0].events.dragover);
    $('.dropzone')[0].removeEventListener('dragleave', myDropzone.listeners[0].events.dragleave);
    $('.dropzone')[0].removeEventListener('dragend', myDropzone.listeners[0].events.dragend);
    
    0 讨论(0)
  • 2020-12-29 08:48

    The Dropzone object has clickable field. That default value is true.

    Depending on your scenario you can either set this to false.

        $('.dropzone').dropzone({
         maxFiles: 10,
         clickable: false,
         init: function() {
    
         }
       });
    
    0 讨论(0)
  • 2020-12-29 08:50

    @XuDing's Answer works like a charm, but I had an edge case where I wanted to keep remove links working so adding an extended solution for that.

    Add below CSS classes

    .dz-max-files-reached {
        pointer-events: none;
        cursor: default;
    }
    .dz-remove { 
        pointer-events: all; cursor: default; 
    }
    
    0 讨论(0)
  • 2020-12-29 08:53

    There is an option field on the Dropzone object called clickable that defaults to true.

    Depending on your scenario you can either set this to false when you register your Dropzone instance or you can update the value at runtime as needed.

    0 讨论(0)
提交回复
热议问题