Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ButtonBar ignores enabled property on labels

Here's a quick demo - am I missing something? mobilesdk 1.2.0

var win = Titanium.UI.createWindow({ 
    backgroundColor:'#fff', 
    barColor: '#660000', 
    tabBarHidden:true
});
// create tab group to manage multiple windows
var tabGroup = Titanium.UI.createTabGroup();
var tab = Titanium.UI.createTab({  
    title:'Bug Demo',
    window:win
});
tabGroup.addTab(tab);
tabGroup.open();

var tc = Ti.UI.createButtonBar({
    labels: [{
        title: 'disabled',
        enabled: false
    },{
        title: 'enabled',
        enabled: true
    }],
    backgroundColor: '#660000'
});
win.rightNavButton = tc;

Update: it turns out that setting the style of the buttonbar to Ti.UI.iPhone.SystemButtonStyle.BAR is what makes this work. So I guess it's iPhone only (of course, the buttonbar usually lives in the iPhone-only title bar or iPhone-only Toolbar, so maybe it's OK that way).

Thanks for giving me a working example to compare to, Clint.

— asked May 7th 2010 by Nick Wing
  • buttonbar
  • disabled
  • enabled
  • iphone
  • mobile
0 Comments

1 Answer

  • Accepted Answer

    this works:

    var buttons = [
        {title:'Disabled', width:100, enabled:false},
        {title:'Enabled', width:100, enabled:true}
    ];
    var buttonBar = Titanium.UI.createButtonBar({
        labels:buttons,
        backgroundColor:'#000',
        top:50,
        left:120,
        style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
        height:40
    });
    
    buttonBar.addEventListener('click', function(e)
    {
        Ti.API.log(e.index);
        // toggle button bar style
         if (e.index == 1) {
            buttons[0].enabled = (buttons[0].enabled==false)?true:false;
            buttonBar.labels = buttons;        
        }
        Ti.API.log('You clicked index = ' + e.index);
    });
    
    win.rightNavButton = buttonBar;
    

    seems that for the properties to be recognized they need to be defined in an external array and then assign the labels array to the other array..

    — answered May 8th 2010 by Clint Tredway
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.