Javascript dropzone.js在查询前检查条件
我正在使用dropzone.js上传图片。 在上传图片之前,用户需要从一个html选择列表中选择一个类别,这样CGI就知道把图片放在哪里了 有没有办法让dropzone在上传之前满足条件,或者有其他方法Javascript dropzone.js在查询前检查条件,javascript,jquery,dropzone.js,Javascript,Jquery,Dropzone.js,我正在使用dropzone.js上传图片。 在上传图片之前,用户需要从一个html选择列表中选择一个类别,这样CGI就知道把图片放在哪里了 有没有办法让dropzone在上传之前满足条件,或者有其他方法 $(function() { Dropzone.options.myAwesomeDropzone = { init: function () { var myDropZone = this;
$(function() {
Dropzone.options.myAwesomeDropzone = {
init: function () {
var myDropZone = this;
$("#btnRemoveAll").click(function () {
myDropZone.removeAllFiles();
}
);
$("#categories").change(function () {
myDropZone.removeAllFiles();
}
);
},
success: function(file,r){
file.previewElement.classList.add("dz-success");
alert(r); // response from server
// this.removeFile(file); // remove file after upload
},
drop:function(){
var tkn=getToken();
$("#token").val(tkn);
var c=$("#categories").val();
$("#cat").val(c);
},
error: function(){
ajaxError();
},
acceptedFiles: "image/jpeg"
};
});
html:
Category:<br>
<select id="categories">
<option value="foo">Please choose</option>
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
</select><br>
New category :<input type="text" id="category">
<form action="cgi/uploadfile.exe"
class="dropzone"
id="my-awesome-dropzone">
<input type="hidden" id="token" name="token">
<input type="hidden" id="cat" name="cat">
</form>
<button id="btnRemoveAll">Clear Dropzone</button>
您可能已经找到了解决方案,但这对我来说很有效: 在表单中添加提交按钮 将autoProcessQueue:false添加到dropzone选项 覆盖submit按钮的click事件,并在通知dropzone处理队列之前检查您的条件:
$('#submit_button').click(function(e) {
e.preventDefault();
e.stopPropagation();
if ( //check your conditions here ) {
myDropzone.processQueue();
} else {
//show error
}
});
您可能已经找到了解决方案,但这对我来说很有效: 在表单中添加提交按钮 将autoProcessQueue:false添加到dropzone选项 覆盖submit按钮的click事件,并在通知dropzone处理队列之前检查您的条件:
$('#submit_button').click(function(e) {
e.preventDefault();
e.stopPropagation();
if ( //check your conditions here ) {
myDropzone.processQueue();
} else {
//show error
}
});
最后你怎么解决呢?我需要解决这个问题:最后你怎么解决?我需要解决这个问题: