Skip to content

Instantly share code, notes, and snippets.

@codescribblr
Created April 15, 2014 13:48
Show Gist options
  • Select an option

  • Save codescribblr/10734268 to your computer and use it in GitHub Desktop.

Select an option

Save codescribblr/10734268 to your computer and use it in GitHub Desktop.
Using jQuery.validate() with bootstrap 3 styles
// override jquery validate plugin defaults
$.validator.setDefaults({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment