extJS RadioGroup setValue() function
Asked Answered
N

6

8

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.

Nonrecognition answered 6/5, 2011 at 7:57 Comment(0)
U
11

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);
Uniocular answered 6/5, 2011 at 8:39 Comment(1)
but how do we use RadioGroup's setValue()? this works for individual ones but what about the overall groupDominique
H
14

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);
            }
        }
    ]
});
Harumscarum answered 23/12, 2013 at 8:51 Comment(0)
U
11

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);
Uniocular answered 6/5, 2011 at 8:39 Comment(1)
but how do we use RadioGroup's setValue()? this works for individual ones but what about the overall groupDominique
E
6

to select 'E-Mail',for example

radios.setValue({communication: 1});

General use:

radioGroup_var.setValue({radioGroup_name: 'inputValue'});
Engedi answered 7/7, 2013 at 13:28 Comment(0)
N
1

This works for me

radios.setValue({communication:<input value>});

Where input value could be the value of the inputValue field of the radio button

Cheers

Notarial answered 11/9, 2012 at 13:17 Comment(0)
H
0

Try passing an array of values to the setValue method like so:

radios.setValue([true, false]);

This will work in ExtJs 3.x not sure about ExtJs4 check the api.

Halfhour answered 6/5, 2011 at 8:40 Comment(0)
S
0

This is an old thread, but Google always finds this first, so I'll just throw my solution (on Ext 3.4.1.1) in here.

Try this:

var radios = new Ext.form.RadioGroup({
    columns: 2,
    name: 'communication', // <== ADD THE NAME AGAIN ON HERE
    items: [
        {boxLabel: 'E-Mail', name: 'communication', inputValue: 1},
        {boxLabel: 'Nagios', name: 'communication', inputValue: 2}
    ]
});

radios.setValue(2); or for a bigger form panel formPanel.getForm().setValues([{communication: 2}]) should work now.

Smoking answered 13/4, 2016 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.