LA_
LA_

Reputation: 20429

How to hide an error message when error is fixed?

I use jQuery Validate plugin and would like to show all errors at one place. I have html like below:

<div class="modal-footer">
  <p class="pull-left hide" id="register-result"></p>
</div>

and javascript:

$("#company").validate({
  errorClass: "error",
  errorElement: "div",
  errorPlacement: function(error, element) {
    $("#register-result").html(error);
    $("#register-result").show();
  },
...

It works almost as expected - the error message is displayed where needed. But when user fixed the error, error message is still displayed. How can I change it?

Upvotes: 1

Views: 119

Answers (2)

Brian Noah
Brian Noah

Reputation: 2972

Make sure you include a success return.

success: function () {
    $('#register-result').fadeOut();
}

Upvotes: 2

Paul Fleming
Paul Fleming

Reputation: 24526

$("#company").validate({
    errorClass: "error",
    errorElement: "div",
    errorPlacement: function(error, element) {
        $("#register-result").html(error);
        $("#register-result").show();
    },
    success: function() {
        $("#register-result").hide();
    }
});

Upvotes: 1

Related Questions