Module: View/Alert


Interface for creating alerts via show and dismiss. Also, this module keeps an internal dictionary of alerts created which can later be accessed by key. This is useful so that client code can dismiss a particular alert.

Note that the client application may provide custom implementation of the View/AlertView class. This implementation will be in charge of rendering the alert to its UI.

At minimum, a client app must provide:

  1. #alerts element in its index.html.
  2. A precompiled template called alert. The template can be compiled at application start-up: app.template.compile('alert', 'template body...');


<static> klass :function

Alert view class.

The default value is View/AlertView. However, if a ViewManager.[Capitalized-appId]AlertView or ViewManager.[Capitalized-platform]AlertView class exists, it will be used instead.

  • function


<static> dismiss(key [, options])

Removes an alert message by key.

Name Type Argument Description
key string

The key provided when previously calling show.

options Object <optional>


<static> dismissAll( [level] [, options])

Removes all alert messages with a given level.

Name Type Argument Description
level string <optional>

Level of alerts to dismiss. If not specified, all alerts are dismissed.

options Object <optional>

Dismissal options.

<static> get(key)

Gets an alert with a given key.

Name Type Description
key string

The key of the alert to retrieve.


Alert view with the specified key.


<static> getAll()

Gets alerts that are currently displayed.


All alerts.


<static> init()

Initializes this module at application start-up.

<static> show(key [, options])

Displays an alert message and adds to the internal dictionary of alerts. Use supplied key later to dismiss the alert. Caller is responsible for using language translation before calling!

To create and close alerts, this function instantiates the View/AlertView class specified by the View.Alert#klass property and places the alert instance in the DOM as the first element in the View.Alert#$alerts element.

The View/AlertView class provides boilerplate implementation for a typical single alert view. You can customize alert behavior by extending the View/AlertView class. At minimum, you have to make sure that a pre-compiled template named 'alert' exists.

In case we are showing a confirmation alert, we want to dismiss all other existing alerts and prevent any other alerts.


const Alert = require('view/alert');
var a1 ='delete_warning', {
    level: 'warning',
    title: 'Warning',
    messages: 'Are you sure you want to delete this record?',
    autoclose: true

var a2 ='internal_error', {
    level: 'error',
    messages: ['Internal Error', 'Response code: 500']
Name Type Argument Description
key string

Index into the cache of defined alert views.

options Object <optional>

The options specified here are handled by the framework.

Name Type Argument Description
level string <optional>

Alert level. alert-[level] class will be added to the alert view.

autoClose boolean <optional>

Boolean flag indicating if the alert must be closed after dismiss delay: See Config#alertAutoCloseDelay setting.

messages string | Array.<string> <optional>


title string <optional>

The title of the alert. It is displayed in bold.


AlertView instance.