Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable text field on checkbox selection ExtJS

Tags:

checkbox

extjs

I'm using ExtJS 3 and I need to enable/disable a specific text field when I select/de-select a checkbox, like in the example showed below:

{ 
    fieldLabel: 'myCheckBox'
    xtype: 'checkbox',
    name: 'myCheckBox'
},{
    fieldLabel: 'myTextField'
    xtype: 'textfield',
    name: 'myTextField',
    disabled: true
}

As I understand it I have to use a listener in 'myCheckBox' like this:

listeners: {
   change: function() {

   }
}

But I don't know what parameters to pass to my function and how to target 'myTextField' and .enable() .disable() it. Can you please help me? Thank you very much.


Solution based on answers (thank you):

listeners: {
     change: function(cb, checked) {
         Ext.getCmp('myTextField').setDisabled(!checked);
 }
 }

and added the id tag to the textfield component like this:

id: 'myTextField'
like image 661
mikethe Avatar asked Mar 01 '13 14:03

mikethe


1 Answers

If you are not sure what to pass as a parameter than Ext.getCmp() gives you the component. It takes id of the component as a parameter. In your case you have to assign id to textfield and can get it on change event as Ext.getCmp('myTextField'). Where myTextField is an id of textfield. Name and Id of a component can be same.

listeners: {
 change: function() {
     Ext.getCmp('myTextField').disable();
     //or
     Ext.getCmp('myTextField').enable();
 }
}
like image 163
Ankit Avatar answered Oct 06 '22 00:10

Ankit