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