Skip to content

Commit

Permalink
improve data-dependent-validation in form-validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander.Frakas committed Jan 15, 2014
1 parent bb2ddb5 commit 7f670cf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/shims/form-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ webshims.register('form-validators', function($, webshims, window, document, und
webshims.customErrorMessages[name][''] = defaultMessage || name;
}
if(formReady){
$('input, select, textarea')
$('input, select, textarea, fieldset[data-dependent-validation]')
.filter(noValidate)
.each(function(){
testValidityRules(this);
Expand All @@ -42,7 +42,7 @@ webshims.register('form-validators', function($, webshims, window, document, und
};
webshims.refreshCustomValidityRules = function(elem){
if(!initTest){return;}

var val;
var data = $(elem).data() || $.data(elem, {});
var customMismatchedRule = data.customMismatchedRule;
var validity = $.prop(elem, 'validity') || {};
Expand Down Expand Up @@ -76,14 +76,18 @@ webshims.register('form-validators', function($, webshims, window, document, und
blockCustom = false;
};
if(customMismatchedRule || validity.valid || (data.dependentValidation && !data.dependentValidation._init)){
var val = $(elem).val();
val = $(elem).val();
$.each(customValidityRules, function(name, test){
message = test(elem, val, data, setMessage) || '';
customMismatchedRule = name;
if(message){
return false;
}
});

if(data.dependentValidation && !data.dependentValidation._init && !data.dependentValidation.masterElement){
customValidityRules.dependent(elem, val, data, $.noop);
}
if(message != 'async' && (message || !validity.valid)){
setMessage(message, customMismatchedRule);
}
Expand All @@ -107,7 +111,7 @@ webshims.register('form-validators', function($, webshims, window, document, und
setTimeout(function(){
webshims.addReady(function(context, selfElement){
initTest = true;
$('input, select, textarea', context).add(selfElement.filter('input, select, textarea'))
$('input, select, textarea, fieldset[data-dependent-validation]', context).add(selfElement.filter('input, select, textarea, fieldset[data-dependent-validation]'))
.filter(noValidate)
.each(function(){
testValidityRules(this);
Expand Down Expand Up @@ -236,7 +240,7 @@ webshims.register('form-validators', function($, webshims, window, document, und


data.masterElement = document.getElementById(data["from"]) || (document.getElementsByName(data["from"] || [])[0]);

data._init = true;
if (!data.masterElement || !data.masterElement.form) {return;}

if(/radio|checkbox/i.test(data.masterElement.type)){
Expand Down

0 comments on commit 7f670cf

Please sign in to comment.