11

I have a button with id of btnAdd and I want to disable it when some event is fired. The event occurs when some window is closed. So I tried the following code and it does not work.

Ext.create('Ext.window.Window', {
    // Some initialization code goes here...
    listeners: {
       close: function(panel, eOpts){
          Ext.get('btnAdd').disable(); // this does not work;
          Ext.get('btnAdd').setDisabled(); // this one does not either
          Ext.get('btnAdd').disabled = true; // And this one also seems to do nothing
       }
    }
});

How can I do that? This may seem to be pretty easy question but don't judge me bad. I'm quite new to Ext JS. I could not find the answer in the API Documentation either.

Dimitri
  • 2,798
  • 7
  • 39
  • 59

4 Answers4

18
Ext.get('btnAdd').setDisabled(true);

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.button.Button-method-setDisabled

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • You solution was true, but I had to change one thing. Instead of Ext.get() I had to use Ext.getCmp(). So Ext.getCmp('btnAdd').setDisabled(true); this one worked perfectly. And can you tell me what is the difference between these two methods? – Dimitri Jun 26 '13 at 07:49
  • @Dima: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext-method-get & http://docs.sencha.com/extjs/4.2.1/#!/api/Ext-method-getCmp – zerkms Jun 26 '13 at 07:53
4

IF the button is Extjs component then use

Ext.getCmp('btnAdd').disable();

If it is not Ext js Component then use

Ext.get('btnAdd').setDisabled(true);

I hope this will help.

2
Ext.get('btnid').disable();
Ext.get('btnid').setDisabled(true);

both return errors, the best way that work without issues is

Ext.getCmp('btnid').setDisabled(true) 

and you can set a text when the button is disabled to notify the user.

Example:

Ext.getCmp('btnid').setText("Button has been disabled")
Dipen Shah
  • 1,911
  • 10
  • 29
  • 45
1
Ext.get('btnid').disable();
Ext.get('btnid').setDisabled(true);
Praveen
  • 55,303
  • 33
  • 133
  • 164