Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've set up the validation summary to update in 'real time' also considering the following:</p> <ol> <li>Update the summary <strong>only</strong> once it's visible (after page validate/submit)</li> <li>Clear the summary when everything is valid</li> </ol> <p>Let's extract the validator, overrride showErrors() and implement our logic:</p> <pre><code>var validator = $('form').data('validator'); validator.settings.showErrors = function (map, errors) { this.defaultShowErrors(); if ($('div[data-valmsg-summary=true] li:visible').length) { this.checkForm(); if (this.errorList.length) $(this.currentForm).triggerHandler("invalid-form", [this]); else $(this.currentForm).resetSummary(); } } </code></pre> <p>Since I'm using this solution for my entire site I've created the following init (onready):</p> <pre><code>$('form').each(function () { var validator = $(this).data('validator'); if (validator) { validator.settings.showErrors = function (map, errors) { this.defaultShowErrors(); if ($('div[data-valmsg-summary=true] li:visible').length) { this.checkForm(); if (this.errorList.length) $(this.currentForm).triggerHandler("invalid-form", [this]); else $(this.currentForm).resetSummary(); } }; } }); </code></pre> <p>And here's the resetSummary used above:</p> <pre><code>jQuery.fn.resetSummary = function () { var form = this.is('form') ? this : this.closest('form'); form.find("[data-valmsg-summary=true]") .removeClass("validation-summary-errors") .addClass("validation-summary-valid") .find("ul") .empty(); return this; }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload