RadioGroup_wev8.js
3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
/**
* @class Ext.form.RadioGroup
* @extends Ext.form.CheckboxGroup
* A grouping container for {@link Ext.form.Radio} controls.
* @constructor
* Creates a new RadioGroup
* @param {Object} config Configuration options
* @xtype radiogroup
*/
Ext.form.RadioGroup = Ext.extend(Ext.form.CheckboxGroup, {
/**
* @cfg {Boolean} allowBlank True to allow every item in the group to be blank (defaults to true).
* If allowBlank = false and no items are selected at validation time, {@link @blankText} will
* be used as the error text.
*/
allowBlank : true,
/**
* @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails
* (defaults to 'You must select one item in this group')
*/
blankText : 'You must select one item in this group',
// private
defaultType : 'radio',
// private
groupCls : 'x-form-radio-group',
/**
* @event change
* Fires when the state of a child radio changes.
* @param {Ext.form.RadioGroup} this
* @param {Ext.form.Radio} checked The checked radio
*/
/**
* Gets the selected {@link Ext.form.Radio} in the group, if it exists.
* @return {Ext.form.Radio} The selected radio.
*/
getValue : function(){
var out = null;
this.eachItem(function(item){
if(item.checked){
out = item;
return false;
}
});
return out;
},
/**
* Sets the checked radio in the group.
* @param {String/Ext.form.Radio} id The radio to check.
* @param {Boolean} value The value to set the radio.
* @return {Ext.form.RadioGroup} this
*/
setValue : function(id, value){
if(this.rendered){
if(arguments.length > 1){
var f = this.getBox(id);
if(f){
f.setValue(value);
if(f.checked){
this.eachItem(function(item){
if (item !== f){
item.setValue(false);
}
});
}
}
}else{
this.setValueForItem(id);
}
}else{
this.values = arguments;
}
return this;
},
// private
fireChecked : function(){
if(!this.checkTask){
this.checkTask = new Ext.util.DelayedTask(this.bufferChecked, this);
}
this.checkTask.delay(10);
},
// private
bufferChecked : function(){
var out = null;
this.eachItem(function(item){
if(item.checked){
out = item;
return false;
}
});
this.fireEvent('change', this, out);
},
onDestroy : function(){
if(this.checkTask){
this.checkTask.cancel();
this.checkTask = null;
}
Ext.form.RadioGroup.superclass.onDestroy.call(this);
}
});
Ext.reg('radiogroup', Ext.form.RadioGroup);