Skip to content

Remove all files with one button

enyo edited this page Apr 2, 2013 · 5 revisions
<form id="my-dropzone" class="dropzone"></form>

<button id="clear-dropzone">Clear Dropzone</button>

<script language="javascript">

  // myDropzone is the configuration for the element that has an id attribute
  // with the value my-dropzone or myDropzone
  Dropzone.options.myDropzone = {
    url: 'dropzoneUploadResized.php', 
    paramName: "file", // The name that will be used to transfer the file
    maxFilesize: 2, // MB
    init: function() {
      this.on("sending", function(file) {
        alert('Sending the file' +  file.name)
      });

      // Using a closure.
      var _this = this;

      // Setup the observer for the button.
      document.querySelector("button#clear-dropzone").addEventObserver("click", function() {
        // Using "_this" here, because "this" doesn't point to the dropzone anymore
        _this.removeAllFiles();
      });
    }
  };

</script>

Thanks to @trinione

Clone this wiki locally