Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(); }
    }
};
like image 971
vicky Avatar asked Dec 18 '25 15:12

vicky


1 Answers

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.

like image 52
Danielle Lpz Avatar answered Dec 20 '25 03:12

Danielle Lpz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!