4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-field-Radio'>/**
19 </span> * @class Ext.form.field.Radio
20 * @extends Ext.form.field.Checkbox
22 Single radio field. Similar to checkbox, but automatically handles making sure only one radio is checked
23 at a time within a group of radios with the same name.
26 In addition to the {@link Ext.form.Labelable standard field labeling options}, radio buttons
27 may be given an optional {@link #boxLabel} which will be displayed immediately to the right of the input. Also
28 see {@link Ext.form.RadioGroup} for a convenient method of grouping related radio buttons.
31 The main value of a Radio field is a boolean, indicating whether or not the radio is checked.
33 The following values will check the radio:
39 Any other value will uncheck it.
41 In addition to the main boolean value, you may also specify a separate {@link #inputValue}. This will be sent
42 as the parameter value when the form is {@link Ext.form.Basic#submit submitted}. You will want to set this
43 value if you have multiple radio buttons with the same {@link #name}, as is almost always the case.
44 {@img Ext.form.Radio/Ext.form.Radio.png Ext.form.Radio component}
47 Ext.create('Ext.form.Panel', {
51 renderTo : Ext.getBody(),
54 xtype : 'fieldcontainer',
56 defaultType: 'radiofield',
81 xtype : 'fieldcontainer',
83 defaultType: 'radiofield',
110 text: 'Smaller Size',
111 handler: function() {
112 var radio1 = Ext.getCmp('radio1'),
113 radio2 = Ext.getCmp('radio2'),
114 radio3 = Ext.getCmp('radio3');
116 //if L is selected, change to M
117 if (radio2.getValue()) {
118 radio1.setValue(true);
122 //if XL is selected, change to L
123 if (radio3.getValue()) {
124 radio2.setValue(true);
128 //if nothing is set, set size to S
129 radio1.setValue(true);
134 handler: function() {
135 var radio1 = Ext.getCmp('radio1'),
136 radio2 = Ext.getCmp('radio2'),
137 radio3 = Ext.getCmp('radio3');
139 //if M is selected, change to L
140 if (radio1.getValue()) {
141 radio2.setValue(true);
145 //if L is selected, change to XL
146 if (radio2.getValue()) {
147 radio3.setValue(true);
151 //if nothing is set, set size to XL
152 radio3.setValue(true);
157 text: 'Select color',
163 handler: function() {
164 var radio = Ext.getCmp('radio4');
165 radio.setValue(true);
170 handler: function() {
171 var radio = Ext.getCmp('radio5');
172 radio.setValue(true);
177 handler: function() {
178 var radio = Ext.getCmp('radio6');
179 radio.setValue(true);
189 * @docauthor Robert Dougan <rob@sencha.com>
192 Ext.define('Ext.form.field.Radio', {
193 extend:'Ext.form.field.Checkbox',
194 alias: ['widget.radiofield', 'widget.radio'],
195 alternateClassName: 'Ext.form.Radio',
196 requires: ['Ext.form.RadioManager'],
200 <span id='Ext-form-field-Radio-cfg-uncheckedValue'> /**
201 </span> * @cfg {String} uncheckedValue @hide
208 <span id='Ext-form-field-Radio-method-getGroupValue'> /**
209 </span> * If this radio is part of a group, it will return the selected value
212 getGroupValue: function() {
213 var selected = this.getManager().getChecked(this.name);
214 return selected ? selected.inputValue : null;
217 <span id='Ext-form-field-Radio-method-onBoxClick'> /**
218 </span> * @private Handle click on the radio button
220 onBoxClick: function(e) {
222 if (!me.disabled && !me.readOnly) {
227 <span id='Ext-form-field-Radio-method-setValue'> /**
228 </span> * Sets either the checked/unchecked status of this Radio, or, if a string value
229 * is passed, checks a sibling Radio of the same name whose value is the value specified.
230 * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
231 * @return {Ext.form.field.Radio} this
233 setValue: function(v) {
237 if (Ext.isBoolean(v)) {
238 me.callParent(arguments);
240 active = me.getManager().getWithValue(me.name, v).getAt(0);
242 active.setValue(true);
248 <span id='Ext-form-field-Radio-method-getSubmitValue'> /**
249 </span> * Returns the submit value for the checkbox which can be used when submitting forms.
250 * @return {Boolean/null} True if checked, null if not.
252 getSubmitValue: function() {
253 return this.checked ? this.inputValue : null;
256 getModelData: function() {
257 return this.getSubmitData();
261 onChange: function(newVal, oldVal) {
263 me.callParent(arguments);
266 this.getManager().getByName(me.name).each(function(item){
268 item.setValue(false);
275 beforeDestroy: function(){
277 this.getManager().removeAtKey(this.id);
281 getManager: function() {
282 return Ext.form.RadioManager;