softwareplay
softwareplay

Reputation: 1409

Dropzone event handling not giving any life sign

i'm using dropzone to build an interface to an online storage api, for uploading files. I've to upload multiple files and to make an ajax call everytime a file is uploaded so that an input field of the hidden form below get added. It's not a big deal for itself, i just have to add a call to the init property of dropzone (i'm not creating a custo dropzone, i'm just using the default one). So at line 1581 i wrote:

  Dropzone.options = {
      init: function() {
            this.on("addedfile", function(file) { alert("added file"); });
          }

};

but when i add i file to the dropzone nothing happens. I'm processing multiple files, so am I calling the wrong event? maybe should i call successmultiple? this is the dropzone tutorial. Any idea?

Upvotes: 1

Views: 651

Answers (1)

Carlos Robles
Carlos Robles

Reputation: 10947

if you have a form, with an id="my-awesome-dropzone" like in the example

<form action="/file-upload"
      class="dropzone"
      id="my-awesome-dropzone"></form>

You have to create a config object in the same document, i.e. in the header

<script src="./path/to/dropzone.js"></script>

<script >
//"myAwesomeDropzone" is the camelized version of the HTML element's ID

Dropzone.options.myAwesomeDropzone = {
  init: function() {
    this.on("addedfile", function(file) { alert("Added file."); });
  }
};

</script>

If instead of this, you are creating the dropzone by

var myDropzone = new Dropzone("form.myFormClass"); //or something like this

you have to add the options as the second parameter

var myDropzone = new Dropzone("form.myFormClass", {
  init: function() {
    this.on("addedfile", function(file) { alert("Added file."); });
  }
});

Upvotes: 1

Related Questions