views:

33

answers:

1

I have a simple radio button:

new Ext.form.Radio({
                    id: 'ptype',
                    boxLabel:'Yes',
                    name: 'price_type',
                    value: 1
                })

However Im having trouble adding a on click event ot it. I usually use:

listeners: {
                click: function (a,e) {
                    //event
                }
}

As a config parameter, however it does not seem to work in this case.

Any advice appreciated, thanks.

+2  A: 

Radio and checkboxes do not have a click event -- I believe you want the check event instead. Your listener should look like:

listeners: {
    check: function (ctl, val) {
        // val is the new checked boolean value
    }
}

Note that the handler config is a handy shortcut for this (also available on buttons). Instead of the listeners syntax you could just do this:

handler: function(ctl, val) {
    // etc
}
bmoeskau
Ah ha, thank you very much!
roobotta
One little problem, the check event only appears to be executed on the first time it is clicked. So for example I had 2 checkboxes and clicked yes, then no, then yes. Check would not be executed on the second yes click. Sorry that Im being stupid but Im on http://www.sencha.com/deploy/dev/docs/source/Radio.html#cls-Ext.form.Radio and cannot find a list of the listeners for the object.
roobotta
You shouldn't look at the source for all supported events as many are inherited from superclasses. Look at the docs instead: http://www.sencha.com/deploy/dev/docs/?class=Ext.form.RadioRadio extends Checkbox -- if you examine the source for Checkbox.setValue you'll see that the check event is raised (and the handler fn called if applicable) any time the value changes, so there must be some issue on your side.
bmoeskau