Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / form / RadioGroup.js
1 /**
2  * @class Ext.form.RadioGroup
3  * @extends Ext.form.CheckboxGroup
4  * <p>A {@link Ext.form.FieldContainer field container} which has a specialized layout for arranging
5  * {@link Ext.form.field.Radio} controls into columns, and provides convenience {@link Ext.form.field.Field} methods
6  * for {@link #getValue getting}, {@link #setValue setting}, and {@link #validate validating} the group
7  * of radio buttons as a whole.</p>
8  * <p><b>Validation:</b> Individual radio buttons themselves have no default validation behavior, but
9  * sometimes you want to require a user to select one of a group of radios. RadioGroup
10  * allows this by setting the config <tt>{@link #allowBlank}:false</tt>; when the user does not check at
11  * one of the radio buttons, the entire group will be highlighted as invalid and the
12  * {@link #blankText error message} will be displayed according to the {@link #msgTarget} config.</p>
13  * <p><b>Layout:</b> The default layout for RadioGroup makes it easy to arrange the radio buttons into
14  * columns; see the {@link #columns} and {@link #vertical} config documentation for details. You may also
15  * use a completely different layout by setting the {@link #layout} to one of the other supported layout
16  * types; for instance you may wish to use a custom arrangement of hbox and vbox containers. In that case
17  * the Radio components at any depth will still be managed by the RadioGroup's validation.</p>
18  * <p>Example usage:</p>
19  * <pre><code>
20 var myRadioGroup = new Ext.form.RadioGroup({
21     id: 'myGroup',
22     xtype: 'radiogroup',
23     fieldLabel: 'Single Column',
24     // Arrange radio buttons into three columns, distributed vertically
25     columns: 3,
26     vertical: true,
27     items: [
28         {boxLabel: 'Item 1', name: 'rb', inputValue: '1'},
29         {boxLabel: 'Item 2', name: 'rb', inputValue: '2', checked: true},
30         {boxLabel: 'Item 3', name: 'rb', inputValue: '3'}
31         {boxLabel: 'Item 4', name: 'rb', inputValue: '4'}
32         {boxLabel: 'Item 5', name: 'rb', inputValue: '5'}
33         {boxLabel: 'Item 6', name: 'rb', inputValue: '6'}
34     ]
35 });
36  * </code></pre>
37  * @constructor
38  * Creates a new RadioGroup
39  * @param {Object} config Configuration options
40  * @xtype radiogroup
41  */
42 Ext.define('Ext.form.RadioGroup', {
43     extend: 'Ext.form.CheckboxGroup',
44     alias: 'widget.radiogroup',
45
46     /**
47      * @cfg {Array} items An Array of {@link Ext.form.field.Radio Radio}s or Radio config objects
48      * to arrange in the group.
49      */
50     /**
51      * @cfg {Boolean} allowBlank True to allow every item in the group to be blank (defaults to true).
52      * If allowBlank = false and no items are selected at validation time, {@link @blankText} will
53      * be used as the error text.
54      */
55     allowBlank : true,
56     /**
57      * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails
58      * (defaults to 'You must select one item in this group')
59      */
60     blankText : 'You must select one item in this group',
61     
62     // private
63     defaultType : 'radiofield',
64     
65     // private
66     groupCls : Ext.baseCSSPrefix + 'form-radio-group',
67
68     getBoxes: function() {
69         return this.query('[isRadio]');
70     }
71
72 });