Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / form / _FormMixin.js

History | View | Annotate | Download (3.62 KB)

1 9 andrej.cim
/*
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["dijit.form._FormMixin"]){
9
dojo._hasResource["dijit.form._FormMixin"]=true;
10
dojo.provide("dijit.form._FormMixin");
11
dojo.require("dojo.window");
12
dojo.declare("dijit.form._FormMixin",null,{reset:function(){
13
dojo.forEach(this.getDescendants(),function(_1){
14
if(_1.reset){
15
_1.reset();
16
}
17
});
18
},validate:function(){
19
var _2=false;
20
return dojo.every(dojo.map(this.getDescendants(),function(_3){
21
_3._hasBeenBlurred=true;
22
var _4=_3.disabled||!_3.validate||_3.validate();
23
if(!_4&&!_2){
24
dojo.window.scrollIntoView(_3.containerNode||_3.domNode);
25
_3.focus();
26
_2=true;
27
}
28
return _4;
29
}),function(_5){
30
return _5;
31
});
32
},setValues:function(_6){
33
dojo.deprecated(this.declaredClass+"::setValues() is deprecated. Use set('value', val) instead.","","2.0");
34
return this.set("value",_6);
35
},_setValueAttr:function(_7){
36
var _8={};
37
dojo.forEach(this.getDescendants(),function(_9){
38
if(!_9.name){
39
return;
40
}
41
var _a=_8[_9.name]||(_8[_9.name]=[]);
42
_a.push(_9);
43
});
44
for(var _b in _8){
45
if(!_8.hasOwnProperty(_b)){
46
continue;
47
}
48
var _c=_8[_b],_d=dojo.getObject(_b,false,_7);
49
if(_d===undefined){
50
continue;
51
}
52
if(!dojo.isArray(_d)){
53
_d=[_d];
54
}
55
if(typeof _c[0].checked=="boolean"){
56
dojo.forEach(_c,function(w,i){
57
w.set("value",dojo.indexOf(_d,w.value)!=-1);
58
});
59
}else{
60
if(_c[0].multiple){
61
_c[0].set("value",_d);
62
}else{
63
dojo.forEach(_c,function(w,i){
64
w.set("value",_d[i]);
65
});
66
}
67
}
68
}
69
},getValues:function(){
70
dojo.deprecated(this.declaredClass+"::getValues() is deprecated. Use get('value') instead.","","2.0");
71
return this.get("value");
72
},_getValueAttr:function(){
73
var _e={};
74
dojo.forEach(this.getDescendants(),function(_f){
75
var _10=_f.name;
76
if(!_10||_f.disabled){
77
return;
78
}
79
var _11=_f.get("value");
80
if(typeof _f.checked=="boolean"){
81
if(/Radio/.test(_f.declaredClass)){
82
if(_11!==false){
83
dojo.setObject(_10,_11,_e);
84
}else{
85
_11=dojo.getObject(_10,false,_e);
86
if(_11===undefined){
87
dojo.setObject(_10,null,_e);
88
}
89
}
90
}else{
91
var ary=dojo.getObject(_10,false,_e);
92
if(!ary){
93
ary=[];
94
dojo.setObject(_10,ary,_e);
95
}
96
if(_11!==false){
97
ary.push(_11);
98
}
99
}
100
}else{
101
var _12=dojo.getObject(_10,false,_e);
102
if(typeof _12!="undefined"){
103
if(dojo.isArray(_12)){
104
_12.push(_11);
105
}else{
106
dojo.setObject(_10,[_12,_11],_e);
107
}
108
}else{
109
dojo.setObject(_10,_11,_e);
110
}
111
}
112
});
113
return _e;
114
},isValid:function(){
115
this._invalidWidgets=dojo.filter(this.getDescendants(),function(_13){
116
return !_13.disabled&&_13.isValid&&!_13.isValid();
117
});
118
return !this._invalidWidgets.length;
119
},onValidStateChange:function(_14){
120
},_widgetChange:function(_15){
121
var _16=this._lastValidState;
122
if(!_15||this._lastValidState===undefined){
123
_16=this.isValid();
124
if(this._lastValidState===undefined){
125
this._lastValidState=_16;
126
}
127
}else{
128
if(_15.isValid){
129
this._invalidWidgets=dojo.filter(this._invalidWidgets||[],function(w){
130
return (w!=_15);
131
},this);
132
if(!_15.isValid()&&!_15.get("disabled")){
133
this._invalidWidgets.push(_15);
134
}
135
_16=(this._invalidWidgets.length===0);
136
}
137
}
138
if(_16!==this._lastValidState){
139
this._lastValidState=_16;
140
this.onValidStateChange(_16);
141
}
142
},connectChildren:function(){
143
dojo.forEach(this._changeConnections,dojo.hitch(this,"disconnect"));
144
var _17=this;
145
var _18=(this._changeConnections=[]);
146
dojo.forEach(dojo.filter(this.getDescendants(),function(_19){
147
return _19.validate;
148
}),function(_1a){
149
_18.push(_17.connect(_1a,"validate",dojo.hitch(_17,"_widgetChange",_1a)));
150
_18.push(_17.connect(_1a,"_setDisabledAttr",dojo.hitch(_17,"_widgetChange",_1a)));
151
});
152
this._widgetChange(null);
153
},startup:function(){
154
this.inherited(arguments);
155
this._changeConnections=[];
156
this.connectChildren();
157
}});
158
}