PDA

View Full Version : beforeexpand usage help



marauder
3 Jan 2011, 5:41 PM
I have a border layout; the center region is collapsible. When the region is collapsed and the user clicks on the expand button. I would like to prompt something simple like "Display center region?" Yes/No. If they click yes, the region expands, otherwise the region remains collapsed.

What is happening that is boggling me; the beforeexpand event is firing and my prompt is showing and the region expands while the prompt is still displayed. How do I get the prompt to "block" per-se to prevent the expand from occurring.



beforeexpand: function(p,a) {
console.log(p);
console.log(a);
Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
if (btn == 'ok'){
Ext.Msg.alert('response', text);
}
});
}

kneth
4 Jan 2011, 1:31 AM
I believe the Ext MessageBox is asynchronous. It does not behave like the native Javascript alert Message dialog. A workaround may be this:



beforeexpand: function(p,a) {
//console.log(p);
//console.log(a);

if (p.expandFlag) {
p.expandFlag = false;
return true; // allows the region to expand
}

Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
if (btn == 'ok'){
//Ext.Msg.alert('response', text);
p.expandFlag = true;
p.expand();
}
});

return false; // prevents the region from expanding
}


Not a pretty good solution but i think it would be fine... :D

marauder
4 Jan 2011, 10:25 AM
Thanks kneth - not pretty but very creative solution. I'm curious - how did you know about the expandFlag and it's use? I don't see any mention of it in the API documentation. Any insight in your thinking process would help greatly, so I don't keep posting questions.

Thanks again for the creative solution.

kneth
4 Jan 2011, 5:41 PM
The expandFlag is something I initialized. It is totally not a part of ext. You can use a global variable instead to avoid confusion. :D