Threaded View

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    7
    Vote Rating
    0
    Answers
    1
    eddyystop is on a distinguished road

      0  

    Default Answered: Why doesn't 'Ext.Msg.alert(...)' work while 'Ext.Msg.prompt()' does?

    Answered: Why doesn't 'Ext.Msg.alert(...)' work while 'Ext.Msg.prompt()' does?


    I'm just starting with Ext JS and trying to understand the why's of the following using Ext4.

    These work:
    Ext.Msg.prompt('...', '...', fn);
    Ext.Msg.show({...});

    But this doesn't work in the latest Chrome and FF:
    Ext.Msg.alert('...', '...', fn);
    Chrome gives the console msg: Cannot call method 'alert' of undefined.
    Why?

    So I'm using:
    Ext.create('Ext.window.MessageBox').alert('...', '...', fn);

  2. Thank you Chamacs.
    The following is my new noobie understanding. I'm most uncertain about the very last paragraph. Please correct me if I'm wrong. Thanks.

    I can use
    Ext.Msg.alert('...', '...', fn);

    (a) with the brute-force way using
    Code:
    <script type="text/javascript" src="../../extjs/ext-all-debug.js"></script>
    or ext-all-dev.js or ext-all.js

    (b) with dynamic loading using
    Code:
    <script type="text/javascript" src="../../extjs/ext-dev.js"></script>
    or ext-debug.js or ext.js
    Code:
    <script type="text/javascript">
    // A leading script tag is used to ensure this is all loaded before
    // the following script starts executing.
    Ext.Loader.setConfig({
        enabled        : true,
        disableCaching : false,
        paths          : {
            // relative path where to find 'Ext.xxx' thingies
            'Ext' : '../../extjs/src'
        }
    });
    // Do asynchronous loading of classes we know we'll need
    Ext.require('Ext.window.MessageBox');
    </script>
    Code:
    <script type="text/javascript">
    Ext.onReady(function () {
    
    
    // Following gives: TypeError: Obj fcn () {...} has no method alert
    // because 'Ext.window.MessageBox' is a class, while
    // 'Ext.MessageBox' is a singleton instance of it, while
    // 'Ext.Msg' is a convenience alternate name for 'Ext.MessageBox'
    //    Ext.window.MessageBox.alert('Hello.', 'The DOM is ready');
    
    
    // Following also work   
    //    Ext.Msg.alert('Hello.', 'The DOM is ready');
    //    Ext.MessageBox.alert('Hello.', 'The DOM is ready');
    
    
    // If Ext.require does not exist above, this synchronously loads the class on demand
    // If Ext.require exists above, Ext.Loader knows class is loaded already
        var win = Ext.create('Ext.window.MessageBox');
        win.alert('Hello.', 'The DOM is ready!'); 
    
    
    });
    </script>
    My main uncertainty: Ext.window.MessageBox is a class (implemented as a function) and so you cannot use .alert on it. Ext.MessageBox and Ext.Msg are the same singleton instance (implemented as an object) of the class (via 'new') and so .alert can be called on them.