-
15 Aug 2012 9:05 AM #1
Answered: Enable comboBox on button click?
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 } });
-
Best Answer Posted by Tim Toady
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.
-
15 Aug 2012 9:33 AM #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.
-
15 Aug 2012 9:40 AM #3


Reply With Quote