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>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
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.
21 * @param {Object} config Configuration options
24 Ext.form.Radio = Ext.extend(Ext.form.Checkbox, {
27 <div id="method-Ext.form.Radio-markInvalid"></div>/**
28 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
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
36 clearInvalid : Ext.emptyFn,
38 <div id="method-Ext.form.Radio-getGroupValue"></div>/**
39 * If this radio is part of a group, it will return the selected value
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;
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){
56 Ext.getCmp(el.dom.id).setValue(false);
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
68 setValue : function(v){
69 if (typeof v == 'boolean') {
70 Ext.form.Radio.superclass.setValue.call(this, v);
72 var r = this.getCheckEl().child('input[name=' + this.el.dom.name + '][value=' + v + ']', true);
74 Ext.getCmp(r.id).setValue(true);
81 getCheckEl: function(){
83 return this.el.up('.x-form-radio-group')
85 return this.el.up('form') || Ext.getBody();
88 Ext.reg('radio', Ext.form.Radio);