-
Get value of radio group
I have got below panel as an item in another panel.
My issue is how to get the 'checked' radio button from this radio group(face). Any help will be highly appreciated. Cheers
Code:
var faceRating = new Ext.Panel({
height:50,
width:160,
//bodyPadding:'0 0 0 20',
//bodyMargin:'0 0 0 10',
layout:{
type:'hbox',
pack:'justify',
},
items:[
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
},
],
});
-
Try this:
Code:
var faceRating = new Ext.form.FormPanel({
fullscreen : true,
height:50,
width:160,
layout:{
type:'hbox',
pack:'justify'
},
items:[
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
value : 'one'
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
value : 'two'
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
value : 'three'
},
{
xtype:'radiofield',
name:'face',
width:40,
cls:'radio_rating',
height:40,
margin:'0 7 0 7',
value : 'four'
}
],
dockedItems : [
{
xtype : 'toolbar',
dock : 'top',
items : [
{
text : 'Get Value',
handler : function() {
var field = faceRating.query('radiofield');
console.log(field[0].getGroupValue());
}
}
]
}
]
});
-
:-/Can I do this without extending FormPanel but Panel?:-/
-
The getGroupValue requires the form.
-
By getting clue from your sample code , I used following code still using Panel . I know it may NOT best in performance factor but did work .
Code:
handler: function(){
var faceRatingValueArray= faceRating.query('radiofield');
var faceRatingValue="";
for(var i=0;i<faceRatingValueArray.length;i++){
if(faceRatingValueArray[i].isChecked())
faceRatingValue=legsRatingValueArray[i].getValue();
}
-
Use getSubmitValue()
I ran into the same problem and then checked the source code for Radio class and it turns out that getValue() method returns either 'true' or 'null'.
Since getGroupValue() calls getValue() in it's return statement it will only return 'true' or 'null'.
This is obviously a bug.
The workaround is to use getSubmitValue() instead.