Skip to content

Commit 670f4b1

Browse files
ntomSergioCrisostomo
ntom
authored andcommitted
Update Form.Validator.Extras.js
Bugfix to validate-reqchk-byname - not hiding error messages properly when one checkbox is unchecked, producing an eror underneath it, then another checkbox is checked, and the previous error doesn't go away. example: http://jsfiddle.net/aUFe4/1/ Update Form.Validator.Extras.js Bugfix to validate-reqchk-byname - not hiding error messages properly when one checkbox is unchecked, producing an eror underneath it, then another checkbox is checked, and the previous error doesn't go away. example: http://jsfiddle.net/aUFe4/1/ Added feature validate-enforce-onselect-value validate-enforce-onselect-value - enables the user to specify when a select value is selected, to enforce / ignore fields remove some unessential code + tab indent cleanup remove some unessential code + tab indent cleanup
1 parent a28974f commit 670f4b1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Source/Forms/Form.Validator.Extras.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ Form.Validator.addAllThese([
5252
return true;
5353
}
5454
}],
55+
56+
['validate-enforce-onselect-value', {
57+
test: function(element, props){
58+
if( !props.value ) return true;
59+
var fv = element.getParent('form').retrieve('validator');
60+
if (!fv) return true;
61+
(props.toEnforce || document.id(props.enforceChildrenOf).getElements('input, select, textarea')).map(function(item){
62+
if (props.value == element.value){
63+
fv.enforceField(item);
64+
} else {
65+
fv.ignoreField(item);
66+
fv.resetField(item);
67+
}
68+
});
69+
return true;
70+
}
71+
}],
5572

5673
['validate-nospace', {
5774
errorMsg: function(){
@@ -107,11 +124,14 @@ Form.Validator.addAllThese([
107124
},
108125
test: function(element, props){
109126
var grpName = props.groupName || element.get('name');
110-
var oneCheckedItem = $$(document.getElementsByName(grpName)).some(function(item, index){
127+
var grpNameEls = $$('[name=' + grpName +']');
128+
var oneCheckedItem = grpNameEls.some(function(item, index){
111129
return item.checked;
112130
});
113131
var fv = element.getParent('form').retrieve('validator');
114-
if (oneCheckedItem && fv) fv.resetField(element);
132+
if (oneCheckedItem && fv) {
133+
grpNameEls.each(function(item, index) { fv.resetField(item); });
134+
}
115135
return oneCheckedItem;
116136
}
117137
}],

0 commit comments

Comments
 (0)