PDA

View Full Version : Ext.getCmp(windowID) is undefined - cannot close Ext.msg.Window because of this!



MagicMatt
9 Nov 2011, 10:27 AM
Hello all,

I am having a very strange issue - one that when implemented the same way works fine on other pages of the application. I know there has to be something relatively simple that I am missing, but I just cannot figure this out.

Here's the problem:

There is a link on the screen that, when clicked, creates an Ext.Window by calling the following javascript function:


function showPopupForm(encryptedId) {
var popWindow = new Ext.Window({
id: 'testPopup',
width: 850,
height: 725,
modal: true,
resizable: false,
draggable: true,
closable: true,
autoScroll: true,
autoLoad:{
url: 'screenXpopup.action',
scripts: true,
params: {
dataId: encryptedId,
}
}
})

popWindow.show();

This part is working correctly. When the user clicks the link on the screen, this Ext.Window shows up and renders the correct page inside of it. On the page within the popup, there is a button that says "Close", and when clicked, should simple close the Ext.Window.

It is a simple as that......but I cannot get it to work for the life of me. When I call Ext.getCmp('testPopup'), it tells me that it is undefined. Here is the javascript that gets executed when the user clicks the button to close the popup (from within the popup):


function closedButtonClicked(){
Ext.getCmp('testPopup').close();
}

That seems pretty straight forward, yet it keeps telling me that 'testPopup' is undefined. How can this be? The window is still showing and active. If I were to call:


Ext.get('testPopup')

then it does give me a reference to the window, but this is on the DOM level (i.e. the div that encapsulates the window, but not the actual window component). So obviously this will not work.



So, anyone have any ideas? I've been stuck on this for almost 2 days with no progress. We use Ext.getCmp() in several other places within the application and it works as expected. Why isn't it working here? What am I doing incorrectly?

Thanks!!!!

skirtle
9 Nov 2011, 8:15 PM
I never use Ext.getCmp with static ids in real code. It's useful for debugging, nothing more. Static ids lead to collisions and then really nasty things happen.

If the button is in the window then just do something like this instead:


handler: function(btn) {
btn.up('window').close();
}

If you want to dig further into your getCmp problem I suggest putting something like this immediately after you create the window:


console.log(popWindow.getId());

Also, try doing a getCmp just before you create the window, check there isn't already one with the same id.

MagicMatt
9 Nov 2011, 9:09 PM
Thanks for the response. And indeed I do not use static IDs in real code. The code I included is just written solely for the purposes of this post - essentially pseudocode. Though I did strip my own code down and use static IDs for debugging along the way - as you noted - with no changed effects.

I will try your suggestion of using a handler and let you know how she fares. But I'd still really like to understand why this isn't working.

I've also already tried calling getCmp() within the showPopupForm function after the window is created, both before and after the show() method is called. It retrieves the window component and I can call .close() or .hide() and it will work as expected. It is as if it is losing track of it outside of that function.

Thanks for your suggestions. Let me know if you've more.

skirtle
9 Nov 2011, 9:25 PM
Add a beforeclose listener to the window and log something. Might be enlightening.

mitchellsimoens
10 Nov 2011, 5:22 AM
What version? Ext.window.MessageBox has gotten recent work done to it.

MagicMatt
10 Nov 2011, 7:11 AM
We are using ExtJS 3

skirtle
10 Nov 2011, 7:13 AM
Moving thread to the ExtJS 3 forum...

FoobarusMaximus
16 Nov 2011, 8:18 AM
I have this same problem with Ext.window.Window in ExtJS 4.0.6.