Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errorClass in jquery validate plugin?

Tags:

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"         }     } }); 
like image 406
djmzfKnm Avatar asked Feb 13 '11 07:02

djmzfKnm


People also ask

How to add error Class in jQuery validation?

validate({ debug: true, errorClass: 'error help-inline', validClass: 'success', errorElement: 'span', highlight: function(element, errorClass, validClass) { $(element). parents("div. control-group"). addClass('error').

How do you check if jQuery validate is working?

The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.

How do you check if all inputs are filled jQuery?

Just use: $("input:empty"). length == 0; If it's zero, none are empty.

Does jQuery validate require a form?

The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form. You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.


1 Answers

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);     } }); 
like image 178
djmzfKnm Avatar answered Sep 17 '22 16:09

djmzfKnm