Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone.js init function() not being called

I have this HTML:

<div id='drop_zone'>
  <div class="close_button" id="removeAllImages">Remove All</div>
  <form action="PHP/uploads.php" class="dropzone" id='fbDropZone'></form>
</div>

and this Javascript in the $(document).ready(function() {}

window.Dropzone;
Dropzone.autoDiscover = false;
$('#fbDropZone').dropzone = {
    init: function() {
     fbDropZone = this;
     $("#removeAllImages").click(function(){fbDropZone.removeAllFiles();})
    },
    paramName: "file",
    maxFilesize: 5,
    maxFiles : 1,
    autoProcessQueue : false,
};

But the init:function() isn't being executed. I can turn autoProcessQueue to false or true and that works so I know the fbDropZone id is correct - but the maxFiles is ignored as well. Have I done a daft syntax error somewhere..? I'm running Safari 7.

like image 916
Todd Avatar asked Mar 04 '14 10:03

Todd


3 Answers

It turns out that the code position is crucial: the dropzone calls have to be placed outside of the document loaded or ready function (I guess you'd call it inline).

like image 68
Todd Avatar answered Oct 21 '22 15:10

Todd


Check that you have to Dropzone.autoDiscover = false outside of your $(document).ready(...).

Wrong:

$(document).ready(function(){
  Dropzone.autoDiscover = false;
  $("#mydropzone").dropzone({
    init: function() {...}
   );
});

Right:

Dropzone.autoDiscover = false;

$(document).ready(function(){
  $("#mydropzone").dropzone({
    init: function() {...}
   );
});
like image 26
Juls Avatar answered Oct 21 '22 15:10

Juls


Try:

Dropzone.autoDiscover = false;
$("#mydropzone").dropzone({
    init: function() {
        var $this = this;
        $("button#clear-dropzone").click(function() {
            $this.removeAllFiles(true);
        });
    },
    paramName: "file",
    maxFilesize: 5,
    maxFiles : 1,
    autoProcessQueue : false
});
like image 27
Breith Avatar answered Oct 21 '22 16:10

Breith