PDA

View Full Version : assign pressed button before it is shown



jep
2 Nov 2010, 3:38 PM
Given the following code:



<html>
<head>
<title>test</title>
<link rel="stylesheet" href="sencha/resources/css/sencha-touch-debug.css" type="text/css">
<script type="text/javascript" src="sencha/ext-touch.js"></script>
</head>

<body>

<script type="text/javascript">

Ext.setup({
onReady: function() {

var select = new Ext.SegmentedButton({
dock:'top',
items: [
{text: 'Option 1'},
{text: 'Option 2'}
]
});

var menubar = new Ext.Toolbar({
dock:'top',
pack:'center',
items:[select],
visible:false
});

var mainPanel = new Ext.Panel({
dockedItems:[],
layout:'vbox',
fullscreen: true,
items:[
{xtype:'button', text:'add',
handler:function () { mainPanel.addDocked(menubar) }},
{xtype:'button', text:'remove',
handler:function () { mainPanel.removeDocked(menubar) }},
{xtype:'button', text:'set',
handler:function () { select.setPressed(1) }}
]
});

}
});

</script>

</body>
</html>


If you click set before you click add, it throws an error (in Safari 5.0.2 XP):
TypeError: Result of expression 'a.el' [undefined] is not an object.

But if you click add, then remove, then set, it works fine. I assume this is because some initialization isn't happening. I've tried calling menubar.doComponentLayout() and doLayout() to try to get it to properly initialize. I've also dug through the other public methods of Toolbar and couldn't find anything applicable.

Is there some way to be able to accomplish this goal?

(Oh, and I know you can set the "pressed" attribute in the config for the startup state, but I'm interested in setting things dynamically at runtime. This is just a very simplified example.)