1 | /* |
---|
2 | * Ext JS Library 2.2.1 |
---|
3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
4 | * licensing@extjs.com |
---|
5 | * |
---|
6 | * http://extjs.com/license |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * @class Ext.form.Radio |
---|
11 | * @extends Ext.form.Checkbox |
---|
12 | * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type. |
---|
13 | * Radio grouping is handled automatically by the browser if you give each radio in a group the same name. |
---|
14 | * @constructor |
---|
15 | * Creates a new Radio |
---|
16 | * @param {Object} config Configuration options |
---|
17 | */ |
---|
18 | Ext.form.Radio = Ext.extend(Ext.form.Checkbox, { |
---|
19 | // private |
---|
20 | inputType: 'radio', |
---|
21 | // private |
---|
22 | baseCls: 'x-form-radio', |
---|
23 | |
---|
24 | /** |
---|
25 | * If this radio is part of a group, it will return the selected value |
---|
26 | * @return {String} |
---|
27 | */ |
---|
28 | getGroupValue : function(){ |
---|
29 | var c = this.getParent().child('input[name='+this.el.dom.name+']:checked', true); |
---|
30 | return c ? c.value : null; |
---|
31 | }, |
---|
32 | |
---|
33 | // private |
---|
34 | getParent : function(){ |
---|
35 | return this.el.up('form') || Ext.getBody(); |
---|
36 | }, |
---|
37 | |
---|
38 | // private |
---|
39 | toggleValue : function() { |
---|
40 | if(!this.checked){ |
---|
41 | var els = this.getParent().select('input[name='+this.el.dom.name+']'); |
---|
42 | els.each(function(el){ |
---|
43 | if(el.dom.id == this.id){ |
---|
44 | this.setValue(true); |
---|
45 | }else{ |
---|
46 | Ext.getCmp(el.dom.id).setValue(false); |
---|
47 | } |
---|
48 | }, this); |
---|
49 | } |
---|
50 | }, |
---|
51 | |
---|
52 | /** |
---|
53 | * Sets either the checked/unchecked status of this Radio, or, if a string value |
---|
54 | * is passed, checks a sibling Radio of the same name whose value is the value specified. |
---|
55 | * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check. |
---|
56 | */ |
---|
57 | setValue : function(v){ |
---|
58 | if(typeof v=='boolean') { |
---|
59 | Ext.form.Radio.superclass.setValue.call(this, v); |
---|
60 | }else{ |
---|
61 | var r = this.getParent().child('input[name='+this.el.dom.name+'][value='+v+']', true); |
---|
62 | if(r && !r.checked){ |
---|
63 | Ext.getCmp(r.id).toggleValue(); |
---|
64 | }; |
---|
65 | } |
---|
66 | }, |
---|
67 | |
---|
68 | /** |
---|
69 | * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide |
---|
70 | * @method |
---|
71 | */ |
---|
72 | markInvalid : Ext.emptyFn, |
---|
73 | /** |
---|
74 | * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide |
---|
75 | * @method |
---|
76 | */ |
---|
77 | clearInvalid : Ext.emptyFn |
---|
78 | |
---|
79 | }); |
---|
80 | Ext.reg('radio', Ext.form.Radio); |
---|