extJS RadioGroup setValue() function

Sapan picture Sapan · May 6, 2011 · Viewed 39.6k times · Source

I have created RadioGroup using the code

var radios = new Ext.form.RadioGroup({
     columns    : 2,
       items: [
             {boxLabel: 'E-Mail', name: 'communication', inputValue: 1},
             {boxLabel: 'Nagios', name: 'communication', inputValue: 2}
        ]
   });

I want to check one of the radio button on some event. How to do it? I tried using:

radios.setValue(true, false);

but it is not working.

Answer

mustafa.0x picture mustafa.0x · Dec 23, 2013

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.RadioGroup-method-setValue

var form = Ext.create('Ext.form.Panel', {
    title       : 'RadioGroup Example',
    width       : 300,
    bodyPadding : 10,
    renderTo    : Ext.getBody(),
    items       : [
        {
            xtype      : 'radiogroup',
            fieldLabel : 'Group',
            items      : [
                { boxLabel : 'Item 1', name : 'rb', inputValue : 1 },
                { boxLabel : 'Item 2', name : 'rb', inputValue : 2 }
            ]
        }
    ],
    tbar        : [
        {
            text    : 'setValue on RadioGroup',
            handler : function () {
                // Set the value of the 'rb' radio butons
                var val = {rb : 2};
                form.child('radiogroup').setValue(val);
            }
        }
    ]
});