use dropzone.options without form

ε祈祈猫儿з 提交于 2021-01-28 04:05:10

问题


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(); }
    }
};

回答1:


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.



来源:https://stackoverflow.com/questions/52222412/use-dropzone-options-without-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!