vicky
vicky

Reputation: 187

use dropzone.options without form

I want to use dropzone on with id. But my Dropzone.options.myid={} is not working. How to validate file type, size in

var myDropzone = new Dropzone("div#myid", { url: "/file/post"});

I cant use tag

console.log file is not working why? My source:

<div id="myid" style="width: 500px; height: 300px; border: 1px solid black">click here</div>

javascript

var myDropzone = new Dropzone("div#myid", { url: "dropzoneupload"});

Dropzone.options.myid = {
    paramName: "file", // The name that will be used to transfer the file
    maxFilesize: 2, // MB
    accept: function(file, done) {
        console.log(file);
        if (file.name == "justinbieber.jpg") {
            done("Naha, you don't.");
        }
        else { done(); }
    }
};

Upvotes: 3

Views: 4079

Answers (1)

Danielle Lpz
Danielle Lpz

Reputation: 322

I don't see where are you using dropzone class to define your dropzone area, does it generate you the default dropzone?

<div id="myDropZone" class="fallback dropzone" enctype="multipart/form-data">
      <input type="file" id="files" class="display" multiple />
</div>

First you need to detach the default dropzone, add this out of you document ready load.

Dropzone.autoDiscover = false;

Then you jquery or js

 var $myDropZone;
 $myDropZone= new Dropzone('div#myDropZone', {*all your settings* 
  addRemoveLinks: true, //to remove
  dictRemoveFile: '<i class="fa fa-times-circle" style="font-weight: 900; 
  cursor:pointer;"></i>' //I used an icon and styled as button so to give a user 
  experience to remove it});

Hope it helps, regards.

Upvotes: 3

Related Questions