Skip to content

Instantly share code, notes, and snippets.

@domenu
Created December 5, 2013 08:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save domenu/7801886 to your computer and use it in GitHub Desktop.
Resets the form's jQuery unobtrusive validation after elements where added dynamically to the form
// Resets the form's jQuery unobtrusive validation after elements where added dynamically to the form
(function ($) {
$.fn.resetUnobtrusiveValidation = function () {
// dynamically added element with unobtrusive validation attributes that was added to the form
var $this = $(this);
// remove unobtrusive validator from the elmement's form
var form = $this.closest("form")
.removeData("validator")
.removeData("unobtrusiveValidation");
// parse the form again, validation is picked up for all elements (also dynamically added elements)
$.validator.unobtrusive.parse(form);
return $this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment