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