Hemant
Hemant

Reputation: 137

extjs: get check value from radio button

I am using radiogroup Yes and No. I want the click value to be sent to server. How to achieve it?

My COde:

{
    fieldLabel: 'Striping',
    xtype: 'radiogroup',
    columns: [50, 100],
    items: [{
        boxLabel: 'Yes',
        name: 'rb',
        id: 'stYes',
        /*checked: true,*/
        inputValue: '1',
        listeners: {
            click: function () {
                alert("Click 2!");
            }
        }

    }, {
        boxLabel: 'No',
        name: 'rb',
        id: 'stNo',
        inputValue: '2',
        listeners: {
            click: function () {
                alert("Click 2!");
            }
        }
    }]
}

Upvotes: 1

Views: 7838

Answers (3)

Leroy
Leroy

Reputation: 472

Just Solved this issue without adding 'name' config in RadioButtons to get the value I just used :

change : function(radioButton,newValue,oldValue){

var newVal = Object.keys(newValue).map(function (key) { return obj[key]; });
var value = newVal[0];
console.log(value)

}

Upvotes: 0

Johan Haest
Johan Haest

Reputation: 4421

I think something like this will work, I can't test this atm. Click won't word for radio buttons, you need to use the change event. Also you better place the listener on your group. Then you don't have to define a listener for each button in your group.

Note: be careful with giving id's to components, use itemId, or name instead.

    {
        fieldLabel: 'Striping',
        xtype:'radiogroup',
        columns: [50, 100],
        items: [{
            boxLabel: 'Yes',
            name: 'rb',
            id: 'stYes',
            /*checked: true,*/
            inputValue: '1'

        }, 
        {
            boxLabel: 'No',
            name: 'rb',
            id: 'stNo',
            inputValue: '2'
        }],
        listeners: {
            change: function( radiogroup, newValue, oldValue, eOpts ) {
                alert(newValue.rb);
            }
        }
    }

Example fiddle: http://jsfiddle.net/johanhaest/cpLvK/7/

Upvotes: 2

Raza Ahmed
Raza Ahmed

Reputation: 2751

.individual will return inputValue which you set in radiogroup items.

 listeners: {
        change: function( radiogroup, newValue, oldValue, eOpts ) {
            alert(newValue.individual);
        }
    }

Upvotes: 0

Related Questions