Results 1 to 3 of 3

Thread: Enable comboBox on button click?

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default Answered: Enable comboBox on button click?

    I have a disabled comboBox in a form panel, and I would like to enable it when the user clicks a button. I have tried to follow the example here regarding Ext.get() but it doesn't work. My entire code is below--the important part is in the onButtonClick function.
    Code:
    Ext.define('MyApp.view.MyForm', {
        extend: 'Ext.form.Panel',
    
    
        height: 250,
        width: 400,
        bodyPadding: 10,
        title: 'My Form',
    
    
        initComponent: function() {
            var me = this;
    
    
            Ext.applyIf(me, {
                items: [
                    {
                        xtype: 'combobox',
                        anchor: '100%',
                        disabled: true,
                        id: 'box',
                        fieldLabel: 'Label'
                    },
                    {
                        xtype: 'button',
                        text: 'MyButton',
                        listeners: {
                            click: {
                                fn: me.onButtonClick,
                                scope: me
                            }
                        }
                    }
                ]
            });
    
    
            me.callParent(arguments);
        },
    
    
        onButtonClick: function(button, e, options) {
            console.log(Ext.get('box'));
            console.log(Ext.get('box').dom.disabled);
            Ext.get('box').dom.disabled = false; // Doesn't work
        }
    
    
    });

  2. So you need to get a reference to the combo and call enable on it. Currently, you are getting a reference to the combo's element and manipulating the dom. The simplest way to achieve what you want (which I don't recommend), is to use Ext.getCmp( 'box' ).enable() in your onButtonClick listener.

    The better way to do this is to do it in your controller. In the this.control call in your controller's init method you should put the click listener on your button. Don't use ids. If you have to, use itemIds instead. I would have a ref for your combo. It would also be good to have an alias on the view so your ref and control selector (component queries) are more specific.

  3. #2
    Sencha User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    603
    Answers
    67
    Vote Rating
    284
      1  

    Default

    So you need to get a reference to the combo and call enable on it. Currently, you are getting a reference to the combo's element and manipulating the dom. The simplest way to achieve what you want (which I don't recommend), is to use Ext.getCmp( 'box' ).enable() in your onButtonClick listener.

    The better way to do this is to do it in your controller. In the this.control call in your controller's init method you should put the click listener on your button. Don't use ids. If you have to, use itemIds instead. I would have a ref for your combo. It would also be good to have an alias on the view so your ref and control selector (component queries) are more specific.

  4. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default

    Very helpful thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •