2

I am trying to disable a button when uploading started in dropzone and enable that button after completion of file upload.

I can enable button in success event. but after starting upload; which event i can disable button?

my code is

    //Simple Dropzonejs 
         $("#dZUpload").dropzone({
             url: "hn_SimpeFileUploader.ashx",
             maxFiles: 100,
             maxFilesize: 2,
             addRemoveLinks: false,
             acceptedFiles: "application/pdf",
             autoProcessQueue: false,                  
             success: function(file, response) {
                  var submit2 = document.getElementById('<%= UploadButton.ClientID %>');
                  submit2.disabled = false;     
                 var imgName = response;
                 file.previewElement.classList.add("dz-success");
                 console.log("Successfully uploaded :" + imgName);

                 var totalfilesize = 0;
                 var obj = {};
                 obj.name = file.name;
                 $.ajax({
                     type: "POST",
                     url: "DUpload.aspx/SendP",
                     data: JSON.stringify(obj),
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function(r) {
                         //alert(r.d);
                     }
                 });

             },
             error: function(file, response) {
                 file.previewElement.classList.add("dz-error");
             }
         });


     });
Jkrish
  • 159
  • 2
  • 16
  • @PranavPatel plz check now. – Jkrish May 06 '16 at 06:11
  • How about [`addedfile`](http://www.dropzonejs.com/#event-addedfile) and [`complete`](http://www.dropzonejs.com/#event-complete) events.. – Rayon May 06 '16 at 06:11
  • complete: will trigger only after the completion of upload. addedfile: is calling multiple times. and also throwing an error. – Jkrish May 06 '16 at 06:43

2 Answers2

0

You can use uploadprogress event and check if the progress is 100. uploadprogress has three parameters: (file, progress, bytesSent)

Besat
  • 1,428
  • 13
  • 27
0

Use processing parameter.

....
processing: function () {
    $('button').prop('disabled', true);
},
success: function (file, response) {
    $('button').prop('disabled', false);
},
....
wpuzman
  • 340
  • 1
  • 5
  • 14