Question

I have a fieldset containing two RadioGroups, each RadioGroup has two RadioFields:

 xtype: 'fieldset',
title: 'Advanced',
autoHeight : true,
id : 'advancedfieldset',
collapsible : true,
width : 280,
margin : 5,
labelWidth : 280,
items : [
    { xtype : 'radiogroup',
    name: 'myGroup',
    vertical: true,
    items :[
         {
          boxLabel : 'duplicate',
          name:'1',
          id:'hid_dup', 
          inputValue: 'Yes'
         },
        {
         boxLabel : 'not duplicate', 
         name: '1',
         id:'hid_not_dup',
         inputValue: 'Yes'
         }
       ]},
    {xtype : 'radiogroup',
    name: 'myGroup2',
    vertical: true,
    items :[{
        boxLabel : 'state',
        name: '2',
        id:'hid_state', 
        inputValue: 'Yes'
        },
       {
        boxLabel : 'not state',
        name: '2',
        id:'hid_not_state',
         inputValue: 'Yes'
       }
]
}
]

I'd like to loop through the fieldset and return the inputvalue of the checked radios of each radiogroup.

I do like this :

var advancedFieldset = parametersRef.down('fieldset[id=advancedfieldset]');

 advancedFieldset.items.each(function (item) {
            if (item.xtype =='combo'){
            filters_values_arr.push(item.getRawValue());
            }else{
                alert(parametersRef.getForm().getValues()[item.name]); //it gives me the two radiofields inputValue (although only one of them is checked) of the FIRST RADIO GROUP ONLY
                alert(item.items.get(1).getGroupValue());//same here
            }
        });

But it's not working, help please!

Was it helpful?

Solution 2

I managed to make it work like this :

advancedFieldset.items.each(function (item) {

            var myGroup= myView.down('radiogroup[name='+item.name+']').getChecked()[0];
              //find the value of the selected Radio button
            alert("Label is: " + myGroup.boxLabel +
               " and Value is: " + myGroup.getGroupValue());            
        });

OTHER TIPS

Is that enough for you? Or I can continue to get specific record based on the ComponentQuery!

Here is the Fiddle : Get selected radio values

Ext.create('Ext.form.Panel', {
    title: 'RadioGroup Example',
    id: 'form-panel',
    width: 300,
    height: 200,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'radiogroup',
            fieldLabel: 'Group One',
            // Arrange radio buttons into two columns, distributed vertically
            columns: 2,
            vertical: true,
            items: [
                { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
                { boxLabel: 'Item 2', name: 'rb', inputValue: '2', checked: true},
                { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
                { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
            ]
        },
        {
            xtype: 'radiogroup',
            fieldLabel: 'Group Two',
            // Arrange radio buttons into two columns, distributed vertically
            columns: 2,
            vertical: true,
            items: [
                { boxLabel: 'Item 1', name: 'cb', inputValue: '1' },
                { boxLabel: 'Item 2', name: 'cb', inputValue: '2' },
                { boxLabel: 'Item 3', name: 'cb', inputValue: '3' },
                { boxLabel: 'Item 4', name: 'cb', inputValue: '4' },
                { boxLabel: 'Item 5', name: 'cb', inputValue: '5' },
                { boxLabel: 'Item 6', name: 'cb', inputValue: '6', checked: true }
            ],
            listeners: {
                change: function() {
                    var fp = Ext.getCmp('form-panel');
                    var out = Ext.ComponentQuery.query('radio');

                    Ext.Array.each(out, function(rb) {
                        if (rb.checked === true) {
                            console.log(rb.inputValue);
                        }
                    })
                }
            }
        }
    ]
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top