Skip to content

Instantly share code, notes, and snippets.

@danielgreen
Last active December 17, 2015 20:49
Show Gist options
  • Save danielgreen/5670068 to your computer and use it in GitHub Desktop.
Save danielgreen/5670068 to your computer and use it in GitHub Desktop.
The jQuery Validation library apparently does not clear or hide the Validation Summary list after a successful validation. If the form is valid and will be submitted to the server, it looks better to hide the list. Use a submitHandler callback to deal with this.
// Set the submitHandler callback via the settings object, as is necessary if you are using Unobtrusive Validation.
// If you are not using Unobtrusive Validation then you can set submitHandler in the options object passed to validate().
$("#iTrentExportForm").validate().settings.submitHandler = function (form) {
BlockPage(); // you may want to block the page during the Ajax call
var container = $(form).find("[data-valmsg-summary=true]"),
list = container.find("ul");
if (list && list.length) {
list.empty();
container.addClass("validation-summary-valid").removeClass("validation-summary-errors");
}
// We amended jquery.validate.js to pass on the return value of this function.
// By returning true this should allow propagation of the submit event to continue.
// This is dependent on the jquery.validate.submithandlerfix.js Gist
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment