Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git] / docs / source / Radio.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.3.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.Radio"></div>/**
16  * @class Ext.form.Radio
17  * @extends Ext.form.Checkbox
18  * Single radio field.  Same as Checkbox, but provided as a convenience for automatically setting the input type.
19  * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
20  * @constructor
21  * Creates a new Radio
22  * @param {Object} config Configuration options
23  * @xtype radio
24  */
25 Ext.form.Radio = Ext.extend(Ext.form.Checkbox, {
26     inputType: 'radio',
27
28     <div id="method-Ext.form.Radio-markInvalid"></div>/**
29      * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
30      * @method
31      */
32     markInvalid : Ext.emptyFn,
33     <div id="method-Ext.form.Radio-clearInvalid"></div>/**
34      * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
35      * @method
36      */
37     clearInvalid : Ext.emptyFn,
38
39     <div id="method-Ext.form.Radio-getGroupValue"></div>/**
40      * If this radio is part of a group, it will return the selected value
41      * @return {String}
42      */
43     getGroupValue : function(){
44         var p = this.el.up('form') || Ext.getBody();
45         var c = p.child('input[name='+this.el.dom.name+']:checked', true);
46         return c ? c.value : null;
47     },
48
49     <div id="method-Ext.form.Radio-setValue"></div>/**
50      * Sets either the checked/unchecked status of this Radio, or, if a string value
51      * is passed, checks a sibling Radio of the same name whose value is the value specified.
52      * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
53      * @return {Ext.form.Field} this
54      */
55     setValue : function(v){
56         var checkEl,
57             els,
58             radio;
59         if (typeof v == 'boolean') {
60             Ext.form.Radio.superclass.setValue.call(this, v);
61         } else if (this.rendered) {
62             checkEl = this.getCheckEl();
63             radio = checkEl.child('input[name=' + this.el.dom.name + '][value=' + v + ']', true);
64             if(radio){
65                 Ext.getCmp(radio.id).setValue(true);
66             }
67         }
68         if(this.rendered && this.checked){
69             checkEl = checkEl || this.getCheckEl();
70             els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
71                         els.each(function(el){
72                                 if(el.dom.id != this.id){
73                                         Ext.getCmp(el.dom.id).setValue(false);
74                                 }
75                         }, this);
76         }
77         return this;
78     },
79
80     // private
81     getCheckEl: function(){
82         if(this.inGroup){
83             return this.el.up('.x-form-radio-group');
84         }
85         return this.el.up('form') || Ext.getBody();
86     }
87 });
88 Ext.reg('radio', Ext.form.Radio);
89 </pre>    
90 </body>
91 </html>