PDA

View Full Version : Radio Help Needed



loveforvdubs
7 Oct 2010, 5:44 AM
I am trying to access the value of a selected radio, it is not in a radio group, it is just a couple of radios with the same name. However, every time i try to access the value i keep coming up with checked.

plalx
7 Oct 2010, 6:18 AM
You need to call getValue() on the specific Ext.form.Radio that you want to know the value of.

I created an example for you showing different ways of fetching form values.



Ext.onReady(function() {
var form = new Ext.form.FormPanel({
renderTo: document.body,
defaults: {
xtype: 'radio',
name: 'test' //Same name for all
},
items: [
{ fieldLabel: 'rad 1', checked: true }, //Rad 1 is checked
{ fieldLabel: 'rad 2' },
{ fieldLabel: 'rad 3' }
],
listeners: {
'afterrender': function() {
var it = this.items.itemAt.createDelegate(this.items),
i;
for (i = 0; i < this.items.getCount(); i++)
console.log('rad ' + (i + 1) , it(i).getValue());
}
}
});

//Returns values as they would be normally submitted with an html form.
//This will always return 'on' if any of the radio with the same name is checked.
console.log('getValues()', form.getForm().getValues());

//Retriving values using getValue() on each fields.
console.log('getFieldValues()', form.getForm().getFieldValues());
});

loveforvdubs
7 Oct 2010, 6:23 AM
Thanks! I think i have the right radio selected. I am using the change event as follows.



MyForm = this;
Ext.iterate(obj.data, function(val, index){
MyForm.get('pos').add({
boxLabel: val.invPO,
columnWidth: 0.5,
itemId: val.invPO,
name: 'PLEASEWORK',
inputValue: val.invPO,
listeners:{
check: function(thisCheckBox,newChecked){
alert(newChecked.getValue());
}
}
});
});