views:

10

answers:

1

Hello. I'm learning how to use the jQuery validation plug-in.

What'd I'd like to do is only show an ICON (css bkg) if the field is valid or in error.

Right now the plugin requires me to add text, but I don't want any...

Ideas?

Code Below:

/* Sign In Form Validation */
$(document).ready(function() { 
    // validate signup form on keyup and submit 
    var validator = $("#user_new").validate({ 
        rules: { 
            'user[fname]': { 
                required: true,
                minlength: 1
            }
        }, 
        messages: { 
            'user[fname]': "Enter your user_fname"
        }, 
        // the errorPlacement has to take the table layout into account 
        errorPlacement: function(error, element) { 
            if ( element.is(":radio") ) 
                error.appendTo( element.parent().next().next() ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo ( element.next() ); 
            else 
                error.appendTo( element.parent().next() ); 
        }, 
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE 
            label.html(" ").addClass("checked"); 
        } 
    }); 

});

I tried blanking out the messages arry like:

            'user[fname]': ""

And if I don't include it, it shows the default error message.

Thanks for any tips.

A: 

Just make it a space, instead of blank.

Dustin Laine
Maybe a non-breaking space to give the container some content/width allowing the backgound to show. May not matter with a `<label>` element, though. Haven't tried it.
tvanfosson
space doesn't work...
Try ` `, as @tvanfosson said. Maybe that the validator is trimming actual white space.
Dustin Laine
That worked. Thank you.... feels like a hack though.
To be honest, I would not recommend using just images for you validation. Not very accessible.
Dustin Laine