errorClass in jquery validate plugin?

前端 未结 6 1039
悲哀的现实
悲哀的现实 2020-12-14 07:58

I am using jquery validate plugin in my web application to validate forms for blank and other simple validations.

I am using below code to setup jquery validate plug

6条回答
  •  -上瘾入骨i
    2020-12-14 08:46

    Thanks, for the tricks guys, but I instead found a better way by using the jQuery code only. There is a highlight event in validate plugin which is called when error occurred to highlight the error fields, I just removed the class form element when this event is called.

    $("#frmSignin").validate({
        debug: false,
        errorClass: "authError",
        errorElement: "span",
        rules: {
            username: {
                required: true,
                minlength: 10
            },
            password: {
                required: true  
            }
        },
        messages: {
            username: {
                required: "Please enter your username"
            },
            password: {
                required: "Please enter your password"
            }
        },
        highlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
        }
    });
    

提交回复
热议问题