I\'m confused with the Bootstrap 3 implementation of form validation. I\'m new to Bootstrap, and I cannot seem to get the form validation working with a form that does not incl
we need to use some kind of external library or custom code to add validation rules, which will enable us to add validation classes to form. I don't think there is other way around.
Example:
http://jsfiddle.net/mapb_1990/hTPY7/9/
HTML:
JS:
$('form').validate({
rules: {
firstname: {
minlength: 3,
maxlength: 15,
required: true
},
lastname: {
minlength: 3,
maxlength: 15,
required: true
}
},
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);
}
}
});