root / trunk / web / dojo / dojox / validate / check.js @ 11
History | View | Annotate | Download (4.93 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.validate.check"]){ |
9 |
dojo._hasResource["dojox.validate.check"]=true; |
10 |
dojo.provide("dojox.validate.check");
|
11 |
dojo.experimental; |
12 |
dojo.require("dojox.validate._base");
|
13 |
dojox.validate.check=function(_1,_2){ |
14 |
var _3=[];
|
15 |
var _4=[];
|
16 |
var _5={isSuccessful:function(){ |
17 |
return (!this.hasInvalid()&&!this.hasMissing()); |
18 |
},hasMissing:function(){ |
19 |
return (_3.length>0); |
20 |
},getMissing:function(){ |
21 |
return _3;
|
22 |
},isMissing:function(_6){ |
23 |
for(var i=0;i<_3.length;i++){ |
24 |
if(_6==_3[i]){
|
25 |
return true; |
26 |
} |
27 |
} |
28 |
return false; |
29 |
},hasInvalid:function(){ |
30 |
return (_4.length>0); |
31 |
},getInvalid:function(){ |
32 |
return _4;
|
33 |
},isInvalid:function(_7){ |
34 |
for(var i=0;i<_4.length;i++){ |
35 |
if(_7==_4[i]){
|
36 |
return true; |
37 |
} |
38 |
} |
39 |
return false; |
40 |
}}; |
41 |
var _8=function(_9,_a){ |
42 |
return (typeof _a[_9]=="undefined"); |
43 |
}; |
44 |
if(_2.trim instanceof Array){ |
45 |
for(var i=0;i<_2.trim.length;i++){ |
46 |
var _b=_1[_2.trim[i]];
|
47 |
if(_8("type",_b)||_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
48 |
continue;
|
49 |
} |
50 |
_b.value=_b.value.replace(/(^\s*|\s*$)/g,""); |
51 |
} |
52 |
} |
53 |
if(_2.uppercase instanceof Array){ |
54 |
for(var i=0;i<_2.uppercase.length;i++){ |
55 |
var _b=_1[_2.uppercase[i]];
|
56 |
if(_8("type",_b)||_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
57 |
continue;
|
58 |
} |
59 |
_b.value=_b.value.toUpperCase(); |
60 |
} |
61 |
} |
62 |
if(_2.lowercase instanceof Array){ |
63 |
for(var i=0;i<_2.lowercase.length;i++){ |
64 |
var _b=_1[_2.lowercase[i]];
|
65 |
if(_8("type",_b)||_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
66 |
continue;
|
67 |
} |
68 |
_b.value=_b.value.toLowerCase(); |
69 |
} |
70 |
} |
71 |
if(_2.ucfirst instanceof Array){ |
72 |
for(var i=0;i<_2.ucfirst.length;i++){ |
73 |
var _b=_1[_2.ucfirst[i]];
|
74 |
if(_8("type",_b)||_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
75 |
continue;
|
76 |
} |
77 |
_b.value=_b.value.replace(/\b\w+\b/g,function(_c){ |
78 |
return _c.substring(0,1).toUpperCase()+_c.substring(1).toLowerCase(); |
79 |
}); |
80 |
} |
81 |
} |
82 |
if(_2.digit instanceof Array){ |
83 |
for(var i=0;i<_2.digit.length;i++){ |
84 |
var _b=_1[_2.digit[i]];
|
85 |
if(_8("type",_b)||_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
86 |
continue;
|
87 |
} |
88 |
_b.value=_b.value.replace(/\D/g,""); |
89 |
} |
90 |
} |
91 |
if(_2.required instanceof Array){ |
92 |
for(var i=0;i<_2.required.length;i++){ |
93 |
if(!dojo.isString(_2.required[i])){
|
94 |
continue;
|
95 |
} |
96 |
var _b=_1[_2.required[i]];
|
97 |
if(!_8("type",_b)&&(_b.type=="text"||_b.type=="textarea"||_b.type=="password"||_b.type=="file")&&/^\s*$/.test(_b.value)){ |
98 |
_3[_3.length]=_b.name; |
99 |
}else{
|
100 |
if(!_8("type",_b)&&(_b.type=="select-one"||_b.type=="select-multiple")&&(_b.selectedIndex==-1||/^\s*$/.test(_b.options[_b.selectedIndex].value))){ |
101 |
_3[_3.length]=_b.name; |
102 |
}else{
|
103 |
if(_b instanceof Array){ |
104 |
var _d=false; |
105 |
for(var j=0;j<_b.length;j++){ |
106 |
if(_b[j].checked){
|
107 |
_d=true;
|
108 |
} |
109 |
} |
110 |
if(!_d){
|
111 |
_3[_3.length]=_b[0].name;
|
112 |
} |
113 |
} |
114 |
} |
115 |
} |
116 |
} |
117 |
} |
118 |
if(_2.required instanceof Array){ |
119 |
for(var i=0;i<_2.required.length;i++){ |
120 |
if(!dojo.isObject(_2.required[i])){
|
121 |
continue;
|
122 |
} |
123 |
var _b,_e;
|
124 |
for(var _f in _2.required[i]){ |
125 |
_b=_1[_f]; |
126 |
_e=_2.required[i][_f]; |
127 |
} |
128 |
if(_b instanceof Array){ |
129 |
var _d=0; |
130 |
for(var j=0;j<_b.length;j++){ |
131 |
if(_b[j].checked){
|
132 |
_d++; |
133 |
} |
134 |
} |
135 |
if(_d<_e){
|
136 |
_3[_3.length]=_b[0].name;
|
137 |
} |
138 |
}else{
|
139 |
if(!_8("type",_b)&&_b.type=="select-multiple"){ |
140 |
var _10=0; |
141 |
for(var j=0;j<_b.options.length;j++){ |
142 |
if(_b.options[j].selected&&!/^\s*$/.test(_b.options[j].value)){ |
143 |
_10++; |
144 |
} |
145 |
} |
146 |
if(_10<_e){
|
147 |
_3[_3.length]=_b.name; |
148 |
} |
149 |
} |
150 |
} |
151 |
} |
152 |
} |
153 |
if(dojo.isObject(_2.dependencies)){
|
154 |
for(_f in _2.dependencies){ |
155 |
var _b=_1[_f];
|
156 |
if(_8("type",_b)){ |
157 |
continue;
|
158 |
} |
159 |
if(_b.type!="text"&&_b.type!="textarea"&&_b.type!="password"){ |
160 |
continue;
|
161 |
} |
162 |
if(/\S+/.test(_b.value)){ |
163 |
continue;
|
164 |
} |
165 |
if(_5.isMissing(_b.name)){
|
166 |
continue;
|
167 |
} |
168 |
var _11=_1[_2.dependencies[_f]];
|
169 |
if(_11.type!="text"&&_11.type!="textarea"&&_11.type!="password"){ |
170 |
continue;
|
171 |
} |
172 |
if(/^\s*$/.test(_11.value)){ |
173 |
continue;
|
174 |
} |
175 |
_3[_3.length]=_b.name; |
176 |
} |
177 |
} |
178 |
if(dojo.isObject(_2.constraints)){
|
179 |
for(_f in _2.constraints){ |
180 |
var _b=_1[_f];
|
181 |
if(!_b){
|
182 |
continue;
|
183 |
} |
184 |
if(!_8("tagName",_b)&&(_b.tagName.toLowerCase().indexOf("input")>=0||_b.tagName.toLowerCase().indexOf("textarea")>=0)&&/^\s*$/.test(_b.value)){ |
185 |
continue;
|
186 |
} |
187 |
var _12=true; |
188 |
if(dojo.isFunction(_2.constraints[_f])){
|
189 |
_12=_2.constraints[_f](_b.value); |
190 |
}else{
|
191 |
if(dojo.isArray(_2.constraints[_f])){
|
192 |
if(dojo.isArray(_2.constraints[_f][0])){ |
193 |
for(var i=0;i<_2.constraints[_f].length;i++){ |
194 |
_12=dojox.validate.evaluateConstraint(_2,_2.constraints[_f][i],_f,_b); |
195 |
if(!_12){
|
196 |
break;
|
197 |
} |
198 |
} |
199 |
}else{
|
200 |
_12=dojox.validate.evaluateConstraint(_2,_2.constraints[_f],_f,_b); |
201 |
} |
202 |
} |
203 |
} |
204 |
if(!_12){
|
205 |
_4[_4.length]=_b.name; |
206 |
} |
207 |
} |
208 |
} |
209 |
if(dojo.isObject(_2.confirm)){
|
210 |
for(_f in _2.confirm){ |
211 |
var _b=_1[_f];
|
212 |
var _11=_1[_2.confirm[_f]];
|
213 |
if(_8("type",_b)||_8("type",_11)||(_b.type!="text"&&_b.type!="textarea"&&_b.type!="password")||(_11.type!=_b.type)||(_11.value==_b.value)||(_5.isInvalid(_b.name))||(/^\s*$/.test(_11.value))){ |
214 |
continue;
|
215 |
} |
216 |
_4[_4.length]=_b.name; |
217 |
} |
218 |
} |
219 |
return _5;
|
220 |
}; |
221 |
dojox.validate.evaluateConstraint=function(_13,_14,_15,_16){ |
222 |
var _17=_14[0]; |
223 |
var _18=_14.slice(1); |
224 |
_18.unshift(_16.value); |
225 |
if(typeof _17!="undefined"){ |
226 |
return _17.apply(null,_18); |
227 |
} |
228 |
return false; |
229 |
}; |
230 |
} |