Created
May 22, 2015 03:02
-
-
Save kzap/5f5a488fb423ab6ffe9c to your computer and use it in GitHub Desktop.
plupload upload before submitting form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client side form validation | |
$("form").submit(function(e) { | |
var uploader = $("#uploader").pluploadQueue(); | |
// Validate number of uploaded files | |
if (uploader.total.uploaded == 0) { | |
// Files in queue upload them first | |
if (uploader.files.length > 0) { | |
// When all files are uploaded submit form | |
uploader.bind("StateChanged", function() { | |
if (uploader.total.uploaded == uploader.files.length) | |
$("form").submit(); | |
}); | |
uploader.start(); | |
} else | |
alert("You must at least upload one file."); | |
e.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment