Skip to content

Commit

Permalink
improved dynamic validation performance
Browse files Browse the repository at this point in the history
  • Loading branch information
frankabbruzzese committed Dec 18, 2016
1 parent e0a427a commit ce6f54a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-validation-unobtrusive-extensions",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/MvcControlsToolkit/Unobtrusive.Extensions",
"description": "Add-on to jQuery Unobtrusive Validation to enable globalization and dynamic content parsing",
"main": [
Expand Down
11 changes: 7 additions & 4 deletions jquery.validate.unobtrusive.dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
var unobtrusiveValidation = form.data('unobtrusiveValidation');
if (!unobtrusiveValidation) return;
var validator = form.validate();

var elements = form[0].elements;
$.each(unobtrusiveValidation.options.rules, function (elname, elrules) {
if (validator.settings.rules[elname] == undefined) {
var args = {};
$.extend(args, elrules);
args.messages = unobtrusiveValidation.options.messages[elname];
$('[name= "' + elname + '"]').rules("add", args);
$(elements.namedItem(elname)).rules("add", args);
} else {
$.each(elrules, function (rulename, data) {
if (validator.settings.rules[elname][rulename] == undefined) {
var args = {};
args[rulename] = data;
args.messages = unobtrusiveValidation.options.messages[elname][rulename];
$('[name= "' + elname + '"]').rules("add", args);
$(elements.namedItem(elname)).rules("add", args);
}
});
}
Expand All @@ -55,7 +55,10 @@
var mvcct = window["mvcct"]||{};
var enhancer = mvcct["enhancer"];
if (enhancer) enhancer.register(function(node, init){
if(init) $.validator.unobtrusive.parse(document);
if(init) {
$.validator.unobtrusive.parse(document);
$('form').removeData('unobtrusiveValidation');
}
else $.validator.unobtrusive.parseDynamic(node);
},
true, null, "unobtrusive validation");
Expand Down
2 changes: 1 addition & 1 deletion jquery.validate.unobtrusive.dynamic.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jquery.validate.unobtrusive.extensions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-validation-unobtrusive-extensions",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/aspnet/jquery-validation-unobtrusive",
"description": "Add-on to jQuery Unobtrusive Validation to enable globalization and dynamic content parsing.",
"main": "jquery.validate.unobtrusive.globalize.min.js",
Expand Down

0 comments on commit ce6f54a

Please sign in to comment.