ons.notification

Utility methods to create different kinds of alert dialogs. There are three methods available:

  • ons.notification.alert()
  • ons.notification.confirm()
  • ons.notification.prompt() It will automatically display a Material Design dialog on Android devices.

Tutorial

Methods Summary

Signature Description
alert(message [, options] | options)

Display an alert dialog to show the user a message. The content of the message can be either simple text or HTML. It can be called in the following ways:

  ons.notification.alert(message, options);
  ons.notification.alert(options);

Must specify either message or messageHTML.

confirm(message [, options] | options)

Display a dialog to ask the user for confirmation. Extends alert() parameters. The default button labels are "Cancel" and "OK" but they can be customized. It can be called in the following ways:

  ons.notification.confirm(message, options);
  ons.notification.confirm(options);

Must specify either message or messageHTML.

prompt(message [, options] | options)

Display a dialog with a prompt to ask the user a question. Extends alert() parameters. It can be called in the following ways:

  ons.notification.prompt(message, options);
  ons.notification.prompt(options);

Must specify either message or messageHTML.

Methods

alert(message [, options] | options): Promise

Display an alert dialog to show the user a message. The content of the message can be either simple text or HTML. It can be called in the following ways:

  ons.notification.alert(message, options);
  ons.notification.alert(options);

Must specify either message or messageHTML.

Returns: Will resolve when the dialog is closed.

Parameters
Name Type Description
message String Alert message. This argument is optional but if it’s not defined either options.message or options.messageHTML must be defined instead.
options Object Parameter object.
options.message String Alert message.
options.messageHTML String Alert message in HTML.
options.buttonLabels String | Array Labels for the buttons. Default is "OK".
options.primaryButtonIndex Number Index of primary button. Default is 0.
options.cancelable Boolean Whether the dialog is cancelable or not. Default is false. If the dialog is cancelable it can be closed by clicking the background or pressing the Android back button.
options.animation String Animation name. Available animations are none and fade. Default is fade.
options.id String The <ons-alert-dialog> element’s ID.
options.class String The <ons-alert-dialog> element’s class.
options.title String Dialog title. Default is "Alert".
options.modifier String Modifier for the dialog.
options.callback Function Function that executes after dialog has been closed.

confirm(message [, options] | options): Promise

Display a dialog to ask the user for confirmation. Extends alert() parameters. The default button labels are "Cancel" and "OK" but they can be customized. It can be called in the following ways:

  ons.notification.confirm(message, options);
  ons.notification.confirm(options);

Must specify either message or messageHTML.

Returns: Will resolve to the index of the button that was pressed.

Parameters
Name Type Description
message String Alert message. This argument is optional but if it’s not defined either options.message or options.messageHTML must be defined instead.
options Object Parameter object.
options.buttonLabels Array Labels for the buttons. Default is ["Cancel", "OK"].
options.primaryButtonIndex Number Index of primary button. Default is 1.

prompt(message [, options] | options): Promise

Display a dialog with a prompt to ask the user a question. Extends alert() parameters. It can be called in the following ways:

  ons.notification.prompt(message, options);
  ons.notification.prompt(options);

Must specify either message or messageHTML.

Returns: Will resolve to the input value when the dialog is closed.

Parameters
Name Type Description
message String Alert message. This argument is optional but if it’s not defined either options.message or options.messageHTML must be defined instead.
options Object Parameter object.
options.buttonLabels String | Array Labels for the buttons. Default is "OK".
options.primaryButtonIndex Number Index of primary button. Default is 0.
options.placeholder String Placeholder for the text input.
options.defaultValue String Default value for the text input.
options.inputType String Type of the input element (password, date…). Default is text.
options.autofocus Boolean Autofocus the input element. Default is true.
options.submitOnEnter Boolean Submit automatically when enter is pressed. Default is true.

Discussion

Need Help?

If you have any questions, use our Community Forum or talk to us via Gitter chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.