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" } } });
validate({ debug: true, errorClass: 'error help-inline', validClass: 'success', errorElement: 'span', highlight: function(element, errorClass, validClass) { $(element). parents("div. control-group"). addClass('error').
The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.
Just use: $("input:empty"). length == 0; If it's zero, none are empty.
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.
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); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With