PDA

View Full Version : Strange behaviour with two connected modal dialogs...



violinista
20 Sep 2007, 6:39 AM
Hello, I noticed a strange issue working with two dialogs: One is showed on main button click, and another is showed when button "Proceed>>" is clicked on first dialog, while first dialog is closed. Here is the working code:



var dialog1,dialog2;

var showDialog1=function(){
if(!dialog1){
dialog1 = new Ext.BasicDialog(null, {
autoCreate: true,
width:400,
height:200,
modal: true,
closable:true,
collapsible:false,
title:'dialog 1'
});
dialog1.addButton({
text:"Proceed>>",
handler:function(){
dialog1.hide();
showDialog2();
}
});
dialog1.addButton({
text:'Cancel',
handler:dialog1.hide
});
}
dialog1.show();
};

var showDialog2=function(){
if(!dialog2){
dialog2 = new Ext.BasicDialog(null, {
autoCreate: true,
width:300,
height:200,
modal: true,
closable:true,
collapsible:false,
title:'dialog 2'
});
dialog2.addButton({
text:'Cancel',
handler:dialog2.hide
});
}
dialog2.show();
};

new Ext.Button(
Ext.DomHelper.append(document.body,{tag:'div'},true),
{
text:'try dialogs',
handler:showDialog1
}
);
So, the scenario is:
-I click on "try dialogs" button, the first modal dialog is shown
-then I click on "Proceed>>" button on first modal, its closed, and showed second dialog.
-When I click on "Cancel" button on second dialog, it is hidden normally,
- and, when I try to click again on "try dialogs" button, the second dialog is showed - not the first!

Do you know what could be the problem?? It makes me mad.

P.S. at the end, when I click on "Cancel" button of wrong displayed second dialog, it closes, but modal DIV remains on the screen, without the chance to do anything on the page. Pretty strange!

Animal
20 Sep 2007, 7:00 AM
Yuo are creating an element with the same id: "null" by passing null as the id of the BasicDialog.

Use Ext.id()

violinista
20 Sep 2007, 7:15 AM
Animal you're the king. Thank you very much.

(The reason I created all of my basicDialogs and layoutDialogs on the similar way (with id of null!) is that I assumed that Ext adds its own Ext.id() when specifying autocreate:true in dialog's config... But I was wrong, and that was source of all my minor problems with dialogs.)

Greetz, cheers

Animal
20 Sep 2007, 7:28 AM
I think it's a "bug" in the BasicDialog constructor. It has



if(!this.el && config && config.autoCreate){
if(typeof config.autoCreate == "object"){
if(!config.autoCreate.id){
config.autoCreate.id = el;
}
this.el = dh.append(document.body,
config.autoCreate, true);
}else{
this.el = dh.append(document.body,
{tag: "div", id: el, style:'visibility:hidden;'}, true);
}
}


So if you pass the first parameter as null, or false, or undefined in order to use an autoCreate or true, or an autoCreate without an id, the bold code will cause the id to be "null", "false", or "undefined".

It should be



if(!this.el && config && config.autoCreate){
if (!el) {
el = Ext.id();
}
if(typeof config.autoCreate == "object"){
if(!config.autoCreate.id){
config.autoCreate.id = el;
}
this.el = dh.append(document.body,
config.autoCreate, true);
}else{
this.el = dh.append(document.body,
{tag: "div", id: el, style:'visibility:hidden;'}, true);
}
}

violinista
20 Sep 2007, 8:00 AM
Yes, I suppose it'll be fixed in next SVN maybe? Anyway, thanks a lot.

Animal
20 Sep 2007, 8:25 AM
Depends if Jack gets to see this thread, and feels it's important enough.