Bootstrap with JQuery Validatation

If you have a problem using JQuery validation with .form-group bootstrap as below :
date_bootstrap

Here the code to initialize the JQuery Validatation

$("#validate-form").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        highlight: function (element) { // hightlight error inputs
            $(element)
                .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group
        },
        unhighlight: function (element) { // revert the change done by hightlight
            $(element)
                .closest('.form-group').removeClass('has-error'); // set error class to the control group
        },
		errorPlacement: function(error, element) {
        if(element.parent('.input-group').length) {
				error.insertAfter(element.parent());
			} else {
				error.insertAfter(element);
			}
		}
    });

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *