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-method-constructor'><span id='Ext-form-field-Radio'>/**
19 </span></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);
190 * Creates a new Radio
191 * @param {Object} config Configuration options
193 * @docauthor Robert Dougan <rob@sencha.com>
196 Ext.define('Ext.form.field.Radio', {
197 extend:'Ext.form.field.Checkbox',
198 alias: ['widget.radiofield', 'widget.radio'],
199 alternateClassName: 'Ext.form.Radio',
200 requires: ['Ext.form.RadioManager'],
204 <span id='Ext-form-field-Radio-cfg-uncheckedValue'> /**
205 </span> * @cfg {String} uncheckedValue @hide
212 <span id='Ext-form-field-Radio-method-getGroupValue'> /**
213 </span> * If this radio is part of a group, it will return the selected value
216 getGroupValue: function() {
217 var selected = this.getManager().getChecked(this.name);
218 return selected ? selected.inputValue : null;
221 <span id='Ext-form-field-Radio-method-onBoxClick'> /**
222 </span> * @private Handle click on the radio button
224 onBoxClick: function(e) {
226 if (!me.disabled && !me.readOnly) {
231 <span id='Ext-form-field-Radio-method-setValue'> /**
232 </span> * Sets either the checked/unchecked status of this Radio, or, if a string value
233 * is passed, checks a sibling Radio of the same name whose value is the value specified.
234 * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
235 * @return {Ext.form.field.Radio} this
237 setValue: function(v) {
241 if (Ext.isBoolean(v)) {
242 me.callParent(arguments);
244 active = me.getManager().getWithValue(me.name, v).getAt(0);
246 active.setValue(true);
252 <span id='Ext-form-field-Radio-method-getSubmitValue'> /**
253 </span> * Returns the submit value for the checkbox which can be used when submitting forms.
254 * @return {Boolean/null} True if checked, null if not.
256 getSubmitValue: function() {
257 return this.checked ? this.inputValue : null;
260 getModelData: function() {
261 return this.getSubmitData();
265 onChange: function(newVal, oldVal) {
267 me.callParent(arguments);
270 this.getManager().getByName(me.name).each(function(item){
272 item.setValue(false);
279 beforeDestroy: function(){
281 this.getManager().removeAtKey(this.id);
285 getManager: function() {
286 return Ext.form.RadioManager;