PDA

View Full Version : Get checkbox current checked or unchecked value



andytt
25 Mar 2014, 6:39 PM
In jQuery, I use
$('#id_of_checkbox').prop('checked') to know whether the checkbox is checked or not.

How can I do this in ExtJS?

I use Ext.form.FormPanel to build checkboxes, when I try to use
jQuery.prop I get always false, no matter it is checked or not.

Here is a piece of code



{
xtype: 'checkbox',
fieldLabel: '<span style="color:red">{remove_product}</span>',id: 'disable_{counter}'
}




form2.findById('disable_'+i).getValue(); //this return undefined


EDIT:

I found out that I can use
getValue() But I CAN'T get correct value, maybe the DOM isn't ready or something?

I try to get value after click a button.

Zinnia
25 Mar 2014, 10:08 PM
{
xtype: 'checkbox',
itemId: 'myCheckBox',
name: 'myChk'
}

you can use the below code to get the value of check box

1. Ext.ComponentQuery.query('checkbox[name=myChk]')[0].getValue();

2.Ext.ComponentQuery.query('#myCheckBox')[0].getValue();

andytt
25 Mar 2014, 10:45 PM
Thanks for applying.

I tried your answer.

But it still return false .. all of checkbox. (I found that some of checkboxes is return correctly sometimes!)

I use getValue() in button onclick handler.

Could that be the reason that I can't get the value?

andytt
25 Mar 2014, 11:48 PM
Sorry

I found that it's db problem, not ext js.

Very appreciate !