Results 1 to 8 of 8

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

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    15
    Vote Rating
    0
      0  

    Question Ext.getCmp(windowID) is undefined - cannot close Ext.msg.Window because of this!

    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:

    Code:
    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):

    Code:
    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:

    Code:
    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!!!!

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    390
      0  

    Default

    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:

    Code:
    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:

    Code:
    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.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default

    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.

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    390
      0  

    Default

    Add a beforeclose listener to the window and log something. Might be enlightening.

  5. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Vote Rating
    1297
      0  

    Default

    What version? Ext.window.MessageBox has gotten recent work done to it.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default

    We are using ExtJS 3

  7. #7
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    390
      0  

    Default

    Moving thread to the ExtJS 3 forum...

  8. #8
    Sencha User
    Join Date
    May 2011
    Posts
    24
    Vote Rating
    0
      0  

    Default

    I have this same problem with Ext.window.Window in ExtJS 4.0.6.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •