View Full Version : Radio button doesnt get initial value

16 Sep 2009, 11:17 PM
I have a group of 3 radio buttons on a page in a formpanel.

I've noticed that the radio button initial state is never set, although
everything else in the form on all the various pages is set. Is there
something special I need to do for radio buttons?

16 Sep 2009, 11:29 PM
First of all you'd better check this example - http://www.extjs.com/deploy/dev/examples/form/check-radio.html. The fieldset with title "Individual radios" have the same what you need. You just should add property to one of radios - "checked:true".

//some code before

items: {
xtype: 'fieldset',
title: 'Individual Radios',
autoHeight: true,
defaultType: 'radio', // each item will be a radio button
items: [{
xtype: 'textfield',
name: 'txt-test2',
fieldLabel: 'Alignment Test'
}, {
checked: true, //this option sets the initial state of radiobutton
fieldLabel: 'Favorite Color',
boxLabel: 'Red',
name: 'fav-color',
inputValue: 'red'
}, {
fieldLabel: '',
labelSeparator: '',
boxLabel: 'Blue',
name: 'fav-color',
inputValue: 'blue'
}, {
fieldLabel: '',
labelSeparator: '',
boxLabel: 'Green',
name: 'fav-color',
inputValue: 'green'

//some code after

or i miss the point?

16 Sep 2009, 11:37 PM
Thanks for the help!

I actually used the 'radiogroup' x-type as the parent of the radio buttons,
and I can set the initial value with a checkbox.

What I couldnt seem to do was transfer the initial value from a datastore to
the radio buttons, although I can save it.

16 Sep 2009, 11:42 PM
My example is similar to this:-

xtype: 'radiogroup',
fieldLabel: 'Multi-Column<br />(custom widths)',
columns: [100, 100],
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'rb-custwidth', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-custwidth', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-custwidth', inputValue: 3},
{boxLabel: 'Item 4', name: 'rb-custwidth', inputValue: 4},
{boxLabel: 'Item 5', name: 'rb-custwidth', inputValue: 5}

Everything works as expected, however I cant set the initial value of
the radio button when this forms part of a form. It always defaults to
'2' as above even if 'rb-custwidth' is say 5.

16 Sep 2009, 11:43 PM
Actually, you just should set "checked:true" for checked radiobutton at the initialization (not only). Try to use Ext.extend and write all logic what you need there.


1. write method, where you will check chosen radiobutton
2. receive the json data with following: "checked:true, 'radiobutton_name or radiobutton_id'"
3. use the method[1] with parameters you've received[2].

16 Sep 2009, 11:49 PM
Is there no way for the form load to do that automatically - like with
a textfield? The save seems to pick of the correct value :)


16 Sep 2009, 11:55 PM
well, i've found following in the API:

Ext.form.RadioGroup -> setValue(String/Ext.form.Radio id, Boolean value ):Ext.form.RadioGroup - Sets the checked radio in the group.

For initial info - read docs.
This is the easiest way ;)

17 Sep 2009, 11:27 PM
Thanks for the help!