PDA

View Full Version : Is it possible to change the UI of a button programmatically?



ed.canas
31 Dec 2010, 3:42 PM
I would to change the UI property of a button from action to decline is this possible?

Right now I have two buttons that I toggle show/hide, but there must be a better way and just have one that changes color.

Thanks,

ed.canas
3 Jan 2011, 5:44 PM
Anybody have any ideas of how this can be done with one button?

Steffen Hiller
3 Jan 2011, 8:06 PM
The 'ui' property just manipulates the button's CSS class name, such as 'x-button-action'.
Try

button.el.removeCls('x-button-action');
button.el.addCls('x-button-decline');

ed.canas
4 Jan 2011, 6:29 AM
Thanks Steffen, just what I was looking for.

gcallaghan
4 Jan 2011, 10:29 AM
I patched the button class to support just such a use case


// Adding setUi method to buttons
Ext.override(Ext.Button,{
setUI:function(ui){
this.removeUI();
this.ui = ui;
this.addCls(this.componentCls + '-' + ui);
this.doComponentLayout();
},
removeUI:function(){
this.removeCls(this.componentCls + '-' + this.ui);
}
});

ed.canas
4 Jan 2011, 12:01 PM
I like the patch, will come very useful. Thanks.