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