Resets the form's jQuery unobtrusive validation after elements where added dynamically to the form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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