finlastudinfo - Sencha Touch: Dialog, Prompt, Alert

Sencha Touch: Dialog, Prompt, Alert

Posted on

Let’s see today what Sencha touch has to offer us in term of showing message, notifications to users. When you are developing any mobile application and need to show some message to user as a pop-up window, or want to take an input from user, or want to display validation messages when user failed to validate form, Ext.MessageBox class is very handy and can be used for this purpose.

Today’s post is to take a look on Sencha touch’s Ext.MessageBox class and its useful functions.

Dialogs:

Ext.MessageBox.show() is used to show the dialog on mobile screen. All display functions (e.g. prompt, alert, confirm) on MessageBox call this function internally, although those calls are basic shortcuts and do not support all of the config options.

To display the basic dialog you need to pass the config object as a parameter to show() method with multiple options. Based on your passed parameter, show method display pop-up dialog accordingly. Most common parameter is button and iconCls property. Button property is used to show the buttons on dialog box and iconCls is used to display icon on the dialog. Code snippet below shows the show method with different parameter values.

Output:

info - Sencha Touch: Dialog, Prompt, Alert

Dialog with multiple buttons

Following code snippet will display multiple buttons on dialog box when you pass buttons: Ext.MessageBox.YESNO to the config object. Take a closer look at iconCls property, its set to ERROR.

Output:

error - Sencha Touch: Dialog, Prompt, Alert

Alert

Ext.MessageBox.alert() is similar to javascript alert() function which display a standard read-only message box with an OK button. If a callback function is passed it will be called after the user clicks the button.

Output:

alert - Sencha Touch: Dialog, Prompt, Alert

Prompt

It displays a message box with OK and Cancel buttons prompting the user to enter some text, similar to JavaScript’s prompt. The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user clicks either button, and the id of the button that was clicked and the text that was entered will be passed as the two parameters to the callback.

Output:

prompt - Sencha Touch: Dialog, Prompt, Alert

That’s all Folks. Happy coding 🙂

Source techzoo.org