Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extJS RadioGroup setValue() function

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.

like image 627
Sapan Avatar asked May 06 '11 07:05

Sapan


2 Answers

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);
            }
        }
    ]
});
like image 54
mustafa.0x Avatar answered Oct 06 '22 22:10

mustafa.0x


radios.items.items should return you the radio buttons inside the radio group. You can then use the setValue() function on them to check or uncheck them.

radios.items.items[index].setValue(true/false);
like image 41
Pulkit Goyal Avatar answered Oct 06 '22 22:10

Pulkit Goyal