我必须使用 dropzone.js 表单,它将几个输入和一个文件上传信息发送到另一个页面。
我的 dropzone 代码如下所示 -->
Dropzone.options.mydropzone = {
maxFiles: 1,
maxFilesize: 10, //mb
acceptedFiles: 'image/*',
addRemoveLinks: true,
autoProcessQueue: false,// used for stopping auto processing uploads
autoDiscover: false,
paramName: 'prod_pic',
previewsContainer: '#dropzonePreview', //used for specifying the previews div
clickable: false, //used this but now i cannot click on previews div to showup the file select dialog box
accept: function(file, done) {
console.log("uploaded");
done();
//used for enabling the submit button if file exist
$( "#submitbtn" ).prop( "disabled", false );
},
init: function() {
this.on("maxfilesexceeded", function(file){
alert("No more files please!Only One image file accepted.");
this.removeFile(file);
});
var myDropzone = this;
$("#submitbtn").on('click',function(e) {
e.preventDefault();
myDropzone.processQueue();
});
this.on("reset", function (file) {
//used for disabling the submit button if no file exist
$( "#submitbtn" ).prop( "disabled", true );
});
}
};
但我只想使预览容器既可单击又可拖放,我已使用它进行了设置previewsContainer: '#dropzonePreview'
, 但不是完整的形式.
如果我使用clickable:false
我无法单击预览 div 来显示文件上传对话框,即使我将文件拖放到表单上的任何位置也是如此。我不希望发生这种情况,我只想拖放预览容器AND可点击,但同时如果我点击提交,则必须上传整个表单。
我已经阅读了这个 dropzone 教程将普通形式与 Dropzone 结合起来 https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone但这只是我真正想做的一半。
我们有什么办法可以使用 Dropzone 有效地实现这一切吗?