Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - errorClass in jquery validate plugin?

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 plugin for my form, there is a erroClass option in it, where I have defined a CSS class name authError which I want to apply on error messages, but its applying the same class to INPUT box as well, I don't want to apply it in INPUT box, just want it for error message. Please check and help. Thanks!

$("#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"
        }
    }
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...