Skip to content

Instantly share code, notes, and snippets.

@dschnare
Last active December 21, 2015 16:59
Show Gist options
  • Save dschnare/6337123 to your computer and use it in GitHub Desktop.
Save dschnare/6337123 to your computer and use it in GitHub Desktop.
jQuery Validate File Fields Quirkiness - Example of how to manually update the valid state of a file field when using jQuery Validate.
// jQuery Validate setup.
$('form').validate({
rules: {
"cover-letter": {
required: true,
accept: "application/pdf|application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
},
messages: {
"cover-letter": "Please upload your cover letter (PDF, DOC or DOCX)."
}
});
// The fix for file fields not re-validating when they change.
$('#cover-letter').change(function () { $(this).valid(); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment