Reputation: 51
I am using dropzone.js working fine for me. It upload files automatically that's cool..... Now I have a problem, I want to disable submit form button till it upload all the files to the server....
I have called Dropzone with basic code....
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.
});
`
etc that upload files to server....
and sample submit form in HTML
<form action="..">
<input type="submit" value="download" />
</form>
Upvotes: 1
Views: 5284
Reputation: 111
combine https://www.dropzonejs.com/#dropzone-methods and submit
$(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;
// }
})
Upvotes: 0
Reputation: 588
You can use the onsending
and queuecomplete
events to toggle the disabled attribute on the form submit button.
For example:
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);
});
Upvotes: 2