Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

webOS Dialogs

Dialogs are found in most modern applications. They are used to inform the user of errors, provide information, or present the user with important choices. Dialogs in Mojo have some interesting capabilities, such as the ability put almost any functionality into a dialog by building it as a scene.

Dialogs are instantiated using controller functions instead of setupWidget().  showDialog() is used to display custom dialogs, and requires both a template and an assistant—the same as a scene.

There are three basic types of dialogs:

  • Error Dialog: Used for presenting error information.
  • Alert Dialog: Used for presenting simple options.
  • Custom Dialog: A custom dialog requires its own scene with its own assistant and scene view file, which generates overhead both from a development perspective and a device resource perspective. When pushed, the dialog scene becomes a child of the invoking scene.

Error Dialog

The error dialog has a fixed title of "Error", a customizable message, and a confirmation button. It is called with a single argument that represents the message displayed.

mojo error dialog

Here is an example of how to set up an error dialog.

Alert Dialog

The alert dialog can display a short message along with one or more HTML buttons presenting selection options.

mojo alert dialog

At time of writing, Palm hasn't yet provided an example of the syntax required to display an alert dialog, however, it should be fairly straightforward. We'll update this article as soon as we have a working example.

Custom Dialog

The showDialog() function displays any content to the user in a modal dialog box. This type of dialog can display almost any web or Mojo UI content.


Here is an example of how to set up the above custom dialog.

Within a custom dialog, swiping back will close the dialog (effectively removing the dialog's scene from the stack), so there is no need for a cancel button, however Palm recommends displaying a cancel button for novice users. The cancel behavior can be blocked with the preventCancel attribute set to true in the showDialog() arguments.

That about does it for dialogs—very handy widgets to have in your programming arsenal.

This article one in a series of daily programming-related webOS articles. Grab the RSS feed to stay in the know!

Much of the information in this article was presented in Chapter 4 of Palm webOS by Mitch Allen.



    Add Comment

      • >:o
      • :-[
      • :'(
      • :-(
      • :-D
      • :-*
      • :-)
      • :P
      • :\
      • 8-)
      • ;-)