Dropzone.js init function() not being called
Asked Answered
B

3

11

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.

Behrens answered 4/3, 2014 at 10:40 Comment(2)
Which Programming language you are using?Curettage
Javascript with a downloaded copy of Dropzone.js.Behrens
B
12

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).

Behrens answered 8/3, 2014 at 9:13 Comment(1)
I think you just saved me a lot of hours!Noeminoesis
S
5

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() {...}
   );
});
Superorganic answered 12/4, 2018 at 19:56 Comment(0)
C
2

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
});
Clog answered 18/8, 2014 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.