yeah its me
yeah its me

Reputation: 1141

JQuery validator how to remove error messages and add border coloring instead

$('.register_form').validate({


     invalidHandler: function(){

        return false;
     }

I've tried this but doesn't worked, how do I remove the error messages, and instead color the input border to red? didn't find examples at docs

Upvotes: 2

Views: 6749

Answers (2)

Sparky
Sparky

Reputation: 98718

Your code:

invalidHandler: function(){
    return false;
}

It doesn't work because the invalidHandler callback has nothing to do with creating, controlling or placing the error label elements. It only fires upon submit when the form is invalid. It's simply the exact opposite of the submitHandler which only fires upon submit of a valid form. See documentation for all callback functions.

The errorPlacement callback function is used to place the error message label elements on the page. If you simply put a return false within this callback function, no error messages will be placed anywhere.

$('.register_form').validate({
    // rules, options, callbacks,
    errorPlacement: function() {
        return false;
    }
});

However, the error and valid classes will still be toggled on the field elements automatically as they are validated. So simply use your CSS to style these as needed.

.error {
    border: 1px solid #f00;
}    
.valid {
    border: 1px solid #0f0;
}

DEMO: http://jsfiddle.net/zqqdV/

Upvotes: 6

Greenhorn
Greenhorn

Reputation: 1700

You can use

errorPlacement: function(){
            return false;
        }

And Css:

.error {
    border: 2px solid #FF4000;
}

.valid {
    border: 2px solid #2EFE2E;
}

Demo Fiddle

Upvotes: 3

Related Questions