4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * @docauthor Robert Dougan <rob@sencha.com>
21 * Single radio field. Similar to checkbox, but automatically handles making sure only one radio is checked
22 * 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.
32 * The main value of a Radio field is a boolean, indicating whether or not the radio is checked.
34 * The following values will check the radio:
41 * Any other value will uncheck it.
43 * In addition to the main boolean value, you may also specify a separate {@link #inputValue}. This will be sent
44 * as the parameter value when the form is {@link Ext.form.Basic#submit submitted}. You will want to set this
45 * value if you have multiple radio buttons with the same {@link #name}, as is almost always the case.
50 * Ext.create('Ext.form.Panel', {
51 * title : 'Order Form',
54 * renderTo : Ext.getBody(),
57 * xtype : 'fieldcontainer',
58 * fieldLabel : 'Size',
59 * defaultType: 'radiofield',
84 * xtype : 'fieldcontainer',
85 * fieldLabel : 'Color',
86 * defaultType: 'radiofield',
100 * inputValue: 'grey',
103 * boxLabel : 'Black',
105 * inputValue: 'black',
113 * text: 'Smaller Size',
114 * handler: function() {
115 * var radio1 = Ext.getCmp('radio1'),
116 * radio2 = Ext.getCmp('radio2'),
117 * radio3 = Ext.getCmp('radio3');
119 * //if L is selected, change to M
120 * if (radio2.getValue()) {
121 * radio1.setValue(true);
125 * //if XL is selected, change to L
126 * if (radio3.getValue()) {
127 * radio2.setValue(true);
131 * //if nothing is set, set size to S
132 * radio1.setValue(true);
136 * text: 'Larger Size',
137 * handler: function() {
138 * var radio1 = Ext.getCmp('radio1'),
139 * radio2 = Ext.getCmp('radio2'),
140 * radio3 = Ext.getCmp('radio3');
142 * //if M is selected, change to L
143 * if (radio1.getValue()) {
144 * radio2.setValue(true);
148 * //if L is selected, change to XL
149 * if (radio2.getValue()) {
150 * radio3.setValue(true);
154 * //if nothing is set, set size to XL
155 * radio3.setValue(true);
160 * text: 'Select color',
166 * handler: function() {
167 * var radio = Ext.getCmp('radio4');
168 * radio.setValue(true);
173 * handler: function() {
174 * var radio = Ext.getCmp('radio5');
175 * radio.setValue(true);
180 * handler: function() {
181 * var radio = Ext.getCmp('radio6');
182 * radio.setValue(true);
191 Ext.define('Ext.form.field.Radio', {
192 extend:'Ext.form.field.Checkbox',
193 alias: ['widget.radiofield', 'widget.radio'],
194 alternateClassName: 'Ext.form.Radio',
195 requires: ['Ext.form.RadioManager'],
199 <span id='Ext-form-field-Radio-cfg-uncheckedValue'> /**
200 </span> * @cfg {String} uncheckedValue @hide
207 <span id='Ext-form-field-Radio-method-getGroupValue'> /**
208 </span> * If this radio is part of a group, it will return the selected value
211 getGroupValue: function() {
212 var selected = this.getManager().getChecked(this.name);
213 return selected ? selected.inputValue : null;
216 <span id='Ext-form-field-Radio-method-onBoxClick'> /**
217 </span> * @private Handle click on the radio button
219 onBoxClick: function(e) {
221 if (!me.disabled && !me.readOnly) {
226 <span id='Ext-form-field-Radio-method-setValue'> /**
227 </span> * Sets either the checked/unchecked status of this Radio, or, if a string value is passed, checks a sibling Radio
228 * of the same name whose value is the value specified.
229 * @param {String/Boolean} value Checked value, or the value of the sibling radio button to check.
230 * @return {Ext.form.field.Radio} this
232 setValue: function(v) {
236 if (Ext.isBoolean(v)) {
237 me.callParent(arguments);
239 active = me.getManager().getWithValue(me.name, v).getAt(0);
241 active.setValue(true);
247 <span id='Ext-form-field-Radio-method-getSubmitValue'> /**
248 </span> * Returns the submit value for the checkbox which can be used when submitting forms.
249 * @return {Boolean/Object} True if checked, null if not.
251 getSubmitValue: function() {
252 return this.checked ? this.inputValue : null;
255 getModelData: function() {
256 return this.getSubmitData();
260 onChange: function(newVal, oldVal) {
262 me.callParent(arguments);
265 this.getManager().getByName(me.name).each(function(item){
267 item.setValue(false);
274 getManager: function() {
275 return Ext.form.RadioManager;