3.5.12.1Creating toast

A widget, script, or UDIX can create its own toast pop-ups using Framework.CreateToast(). For example:

Framework.CreateToast({

title: "Finished!",

text: "The task has been completed",

icon: "f05a"

});

CreateToast() can also be called with a string parameter. This is then treated as {text: <string>}. For example:

// These two calls are identical:

Framework.CreateToast("My message");

Framework.CreateToast({text: "My message"});

The standard properties of the toast definition are as follows:

Property

Description

text

Body text of the notification

title

Title for the notification. (Not compulsory.)

icon

Hexadecimal code of an icon in the FontAwesome set, such as "f05a" for an info icon. (Not compulsory.)

Framework.CreateToast() can have a callback function. This is called if the user clicks on the toast notification and/or when the toast is destroyed. For example:

Framework.CreateToast({

title: "Finished!",

text: "The task has been completed",

icon: "f05a"

}, function (ToastMsg) {

if (ToastMsg.clicked) {

// User has clicked on the toast

} else {

// The toast is being destroyed

}

});

The ToastMsg which is passed to the callback function has the following properties:

Property

Description

clicked

Indicates whether the message is the result of a click. If not, then it means that the toast is being destroyed and no further messages will be sent.

toastId

ID assigned to the toast

toast

Definition of the toast, as originally passed in to CreateToast()

By default, a toast notification is destroyed if the user clicks on it. Therefore, unless you modify the standard behaviour using the properties described below, if the user clicks on the toast then there will be two messages: a click message with clicked:true and then a destruction message with clicked:false.

Other properties which you can use to modify the toast are as follows:

Property

Description

lifespan

Lifespan of the toast in seconds, overriding the app's default

toastId

Optional ID to assign to the toast, so that the toast has a known ID which can be manually destroyed. Callers are recommended to use FXB.utils.GenerateGuid().

noDestroyOnClick

Prevents the toast being automatically destroyed when the user clicks on it. The caller can destroy it manually (rather than waiting for its natural expiry) by implementing a click callback and using that to destroy the toast.

toastCreationGroup

Ignored if blank/null. Suppresses creation of this new toast if there are any existing items with the same toastCreationGroup value.

toastReplacementGroup

Ignored if blank/null. The opposite of toastCreationGroup. If there are any existing items with the same toastReplacementGroup value, they are destroyed (and replaced by this new toast).

toastClickGroup

Ignored if blank/null. Automatically destroys all the items with the same toastClickGroup value when any one of them is clicked on.

toastClass

Optional display class for the toast, changing its formatting. Currently available values are ToastSuccess and ToastError.

dialog

Optional description of a dialog to display in response to a click on the toast. See below.