【发布时间】:2014-04-06 13:13:12
【问题描述】:
我必须使用 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 );
});
}
};
但我只想将 Previews 容器设置为 Clickable 和 Drag and Drop ,这是我使用 previewsContainer: '#dropzonePreview' 设置的,但不是整个表单。
如果我使用clickable:false,我将无法单击预览 div 以显示文件上传对话框,即使我将文件拖放到表单上的任何位置也是如此。我不希望这种情况发生,我只想拖放预览容器并且可点击,但同时如果我点击提交,则必须上传整个表单。
我已经阅读了这个 dropzone 教程Combine normal form with Dropzone,但这只是我真正想做的一半。
我们有什么方法可以有效地使用 Dropzone 实现所有这些吗?
【问题讨论】:
标签: javascript jquery forms file-upload dropzone.js