Validation plugin - how to use custom classes?
Hi,
I've been going round and round in circles with this for the last 2 hours, and its driving me up the wall.
I'm using this plugin: http://docs.jquery.com/Plugins/Validation . I've attached a screenshot of what happens upon a "successful" value being entered.
With the following CSS classes:
- .valid {
- padding-top: 4px;
- background: #ffffff url('/bootstrap/assets/img/valid.png') right center no-repeat;
-
- }
- .error {
- font-weight: bold;
- color: red;
- padding: 2px 8px;
- margin-top: 2px;
- }
- input[type="password"], input[type="text"] {
- padding-right:20px;
- }
Then the following JS code:
- $("#registerForm").validate({
- rules: {
- FirstName: {
- required: true
- },
- LastName: {
- required: true
- },
- Email: {
- required: true,
- email: true
- },
- Password: {
- required: true,
- minlength: 4
- }
- },
- messages: {
- FirstName: "Enter your firstname",
- LastName: "Enter your lastname",
- Password: {
- required: "Provide a password",
- rangelength: jQuery.format("Enter at least {0} characters")
- },
- Email: {
- required: "Please enter a valid email address",
- minlength: "Please enter a valid email address"
- },
- },
- success: function(label) {
- var theparent = $(label).parent();
- $(theparent).addClass("valid").removeClass("error");
- },
- submitHandler: function(form) {
- $("#ccInfoError").hide();
- $.post("/cgi-bin/art/joinnew.cgi", $("#registerForm").serialize() , function(data) {
- if (data == "BAD_INFO" || data == "INVALID_CVV") {
- $("#ccInfoError").show().html("Please check your payment information is all filled out");
- } else if (data == "INVALID_CARD_NUMBER") {
- $("#ccInfoError").show().html("Please Credit Card number appears to be an invalid format. Please check");
- } else if (data == "DONE") {
- document.location.href= "/cgi-bin/page.cgi?p=register_success";
- } else {
- $("#ccInfoError").show().html(data);
- }
- });
- return false;
- }
- });
It kinda works, as it adds the "valid" class fine to the input BUT it also adds it as a label as well! I don't want it to use a label... I wanna add it to the CSS class itself (so I can remove it in other parts of my code if needed with removeClass() )
Can anyone suggest where I'm going wrong? I've tried so many things I've actually lost track!
TIA
Andy