3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.form.Radio
9 * @extends Ext.form.Checkbox
10 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
11 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
14 * @param {Object} config Configuration options
17 Ext.form.Radio = Ext.extend(Ext.form.Checkbox, {
21 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
24 markInvalid : Ext.emptyFn,
26 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
29 clearInvalid : Ext.emptyFn,
32 * If this radio is part of a group, it will return the selected value
35 getGroupValue : function(){
36 var p = this.el.up('form') || Ext.getBody();
37 var c = p.child('input[name='+this.el.dom.name+']:checked', true);
38 return c ? c.value : null;
42 * Sets either the checked/unchecked status of this Radio, or, if a string value
43 * is passed, checks a sibling Radio of the same name whose value is the value specified.
44 * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
45 * @return {Ext.form.Field} this
47 setValue : function(v){
51 if (typeof v == 'boolean') {
52 Ext.form.Radio.superclass.setValue.call(this, v);
53 } else if (this.rendered) {
54 checkEl = this.getCheckEl();
55 radio = checkEl.child('input[name=' + this.el.dom.name + '][value=' + v + ']', true);
57 Ext.getCmp(radio.id).setValue(true);
60 if(this.rendered && this.checked){
61 checkEl = checkEl || this.getCheckEl();
62 els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
63 els.each(function(el){
64 if(el.dom.id != this.id){
65 Ext.getCmp(el.dom.id).setValue(false);
73 getCheckEl: function(){
75 return this.el.up('.x-form-radio-group');
77 return this.el.up('form') || Ext.getBody();
80 Ext.reg('radio', Ext.form.Radio);