Search code examples
sencha-touchsencha-touch-2

Can't display an alert using MessageBox in Sencha Touch 2


In a handler in one of my controllers, I'm running into issues displaying a simple alert message. Using Sencha Touch 2.4.1

Ext.Msg.alert('Status', 'test');
--> "Uncaught TypeError: Cannot read property 'alert' of undefined"

As per these instructions, I added the following require statement: Ext.window.MessageBox to my controller.
--> Failed to find any files for /PATH/FILE.js::ClassRequire::Ext.window.MessageBox

Replaced Msg with MessageBox and removed require statement.
Ext.MessageBox.alert('Status', 'test')
--> "Uncaught TypeError: undefined is not a function"

Ran into the same problem when using .confirm.

Here's the docs - looks like it should work.

Anybody know why it doesn't?


Solution

  • I needed to require Ext.MessageBox instead of Ext.window.MessageBox and had to use Ext.Msg.alert... instead of Ext.MessageBox.alert... though I'm not totally clear on why.

    Saw this in the docs: "The framework provides a global singleton Ext.Msg for common usage which you should use in most cases."