codemonkey613
codemonkey613

Reputation: 998

jQuery validation plugin - hide error label on field focus

I would like error labels to appear when user clicks Submit. But then when user focuses on a field, the error messages go away, even if there is an error still. User will see the error messages next when he clicks submit again.

How can I turn off the default feature? (Right now, there errors appear onsubmit, then won't go away until the error is gone. But I'm working with limited spaces, I'm placing the label right above the input field, so I need the label to disappear when the field is selected.)

Thanks

Upvotes: 1

Views: 2403

Answers (2)

Paul Alexander
Paul Alexander

Reputation: 32367

The default behavior is to insert the validation element immediately after the input in the DOM. So you can use CSS to hide the label

input:focus + .field-validation-error { display: none; }

Upvotes: 0

James Hulse
James Hulse

Reputation: 1581

You could manually hide the message yourself by attaching a function to .focus() to hide the validation message for that field. Something like (untested):

$(function() {
    $("input").focus(function() {
        $(this).prev().hide();
    });
});

Upvotes: 1

Related Questions