Skip to content

Instantly share code, notes, and snippets.

@kzap
Created May 22, 2015 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzap/5f5a488fb423ab6ffe9c to your computer and use it in GitHub Desktop.
Save kzap/5f5a488fb423ab6ffe9c to your computer and use it in GitHub Desktop.
plupload upload before submitting form
// 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