Check a radio button using ExtJS
Asked Answered
T

3

5

I may be missing something, but how do I programmatically check a radiobutton using ExtJS (v 3)?

The following doesn't seem to always work

var radio = Ext.get("myradiobutton");

radio.set("checked,"");

The radio is sometimes checked, sometimes not...

radio.is(":checked") sometimes return true, sometimes false

Thanks

Trixi answered 29/2, 2012 at 8:31 Comment(0)
I
6

Why not just use the DOM?

Ext.getDom('myradio').checked = true;
Iodize answered 29/2, 2012 at 8:39 Comment(3)
Yes, this does work as a work around, but isn't there an ExtJs way of doing it ?Trixi
@Evan: I am curious, why recommend using the DOM directly instead of going straight ExtJS? I see from David's other comments that he's not using an ExtJS RadioButton, but my question assumes that it is an ExtJS RadioButton.Azzieb
In the end (overly simply), Ext is just a wrapper around a bunch of DOM functions. If it's easy and it works cross browser, why not?Iodize
A
13

I'd suggested using this function: http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.Radio-method-setValue

var radio = Ext.get("myradiobutton");
radio.setValue(true);
Ancier answered 29/2, 2012 at 8:54 Comment(5)
I'm using ExtJS 3, which does not have that methodTrixi
Ext.get() returns an Ext.Element reference, not a component. -1Iodize
Also, my radio is not an ExtJs form radio, just a normal radio buttonTrixi
This works as well: Ext.getCmp('myradiobutton').setValue(true);Ils
I tried both radio.checked and radio.setValue(true), only the radio.setValue(true) worked for me, at the same time it triggered the event change. I am using xtype=radio btw.Horary
I
6

Why not just use the DOM?

Ext.getDom('myradio').checked = true;
Iodize answered 29/2, 2012 at 8:39 Comment(3)
Yes, this does work as a work around, but isn't there an ExtJs way of doing it ?Trixi
@Evan: I am curious, why recommend using the DOM directly instead of going straight ExtJS? I see from David's other comments that he's not using an ExtJS RadioButton, but my question assumes that it is an ExtJS RadioButton.Azzieb
In the end (overly simply), Ext is just a wrapper around a bunch of DOM functions. If it's easy and it works cross browser, why not?Iodize
T
1

For me it worked using the getCmp and setValue functions.

Ext.getCmp('yourid').setValue(true);
Tedesco answered 6/4, 2021 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.