jQuery Validate: add error or validate class to parent div

前端 未结 3 1766
不知归路
不知归路 2020-12-10 06:53

I am using Twitter\'s Bootstrap as my framework for a project I am working on. I am attempting to validate a simple contact form using the jQuery Validate plugin but it\'s c

3条回答
  •  悲哀的现实
    2020-12-10 07:34

    I might be wrong but it looks like you need .parents('div.control-group') not .parent(), which adds .error to the wrong div not changing BootStraps form colors to red.

    This is because the input that JQuery Validate is trying to highlight is two below the .control-group that BootStrap requires for .error to take its effect.

    $("#form").validate({
        highlight: function(element, errorClass, validClass){
        $(element).parents("div.control-group").addClass(errorClass).removeClass(validClass);
    },
    

    Hope this helps

提交回复
热议问题