我正在使用dropzone.js正常工作。它自动上传文件很酷.....现在我有一个问题,我想禁用提交表单按钮,直到它将所有文件上传到服务器....
我用基本代码调用Dropzone ....
jQuery(function () {
Dropzone.autoDiscover = false;
var myDropzoneOptions = {
maxFilesize: 15,
addRemoveLinks: true,
acceptedFiles: 'image/*, .pdf, .doc, .docx,.xls,.xlsx,.csv,.txt',
// acceptedFiles:'image/* , text/pdf ,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation',
clickable: true,
url: "<?php bloginfo('siteurl') ?>/?my_upload_of_task_files2=1",
};
var myDropzone = new Dropzone('div#myDropzoneElement2', myDropzoneOptions);
myDropzone.on("sending", function (file, xhr, formData) {
formData.append("author", "<?php echo $cid; ?>"); // Will send the filesize along with the file as POST data.
formData.append("ID", "<?php echo $pid; ?>"); // Will send the filesize along with the file as POST data.
});
`
等将文件上传到服务器....
并以HTML格式提交表单
<form action="..">
<input type="submit" value="download" />
</form>
您可以使用onsending
和queuecomplete
事件在表单提交按钮上切换已禁用的属性。
例如:
myDropzone.on("sending", function (file, xhr, formData) {
// Disable the submit button
$(":submit").prop("disabled", true);
formData.append("author", "<?php echo $cid; ?>"); // Will send the filesize along with the file as POST data.
formData.append("ID", "<?php echo $pid; ?>"); // Will send the filesize along with the file as POST data.
});
myDropzone.on("queuecomplete", function ( ) {
// Re-enable the submit button
$(":submit").prop("disabled", false);
});
结合https://www.dropzonejs.com/#dropzone-methods并提交
$(form).submit(function () {
if (youDropZone.getUploadingFiles().length != 0) {
return false;
}
// if your file field is required additional check if .getAcceptedFiles() == 0
// if (
// youDropZone.getUploadingFiles().length != 0
// || youDropZone.getAcceptedFiles() == 0
// ) {
// return false;
// }
})