keeehlan
keeehlan

Reputation: 8054

ValidationSummary stays visible after errors are corrected?

I have a ValidationSummary that works pretty well, although it doesn't go away after the last of the form errors are rectified.

I'm not sure if this is default behavior or a bug. It seems more towards the latter, since they don't go away after my form has been submitted.

The only thing I suspect might be impacting the functionality is that the form is created through Ajax.BeginForm().

Even still, shouldn't the ValidationSummary disappear right as I hit the submit button?

Upvotes: 6

Views: 4748

Answers (2)

Gavin
Gavin

Reputation: 124

This is an example of something I've used prior, hopefully it helps anyone who finds this. I kinda disagree with the accepted answer as it breaks the usability of the summary later.

$("form#AJAX_FormA").on('submit', function (e) {
    e.preventDefault();
    $(this).validate();
    if ($(this).valid()) {
        $('.validation-summary-errors ul li').attr("style", "display:none"); //Hide
        $('.validation-summary-errors').removeClass("validation-summary-errors").addClass("validation-summary-valid");
        ajaxGenerateList($(this).serialize());
    }
});

Upvotes: 1

mnsr
mnsr

Reputation: 12437

You can make it hide on form submit in your javascript. If you inspect element on your validation summary, you'll notice it changes styles from .validation-summary-valid to .validation-summary-errors if there are any errors. So this makes it easy to hide.

e.g.

$('#formName').submit(function() {
    if ($(this).valid()) { // checks form is valid.
        $('.validation-summary-errors').hide(); // hides it
    }
});

Upvotes: 9

Related Questions