hub.eb?material_id=377&track_id=368

Adding Messages to Controls


There are two ways to add a message to a Control:

  1. by passing in a string:
  2. by passing in a Text:

A Text can have multiple substitutions in it, e.g. "You cannot order && with &&". Any double ampersands (&&) present in the Text can be substitued for a value, provided in an array as a separate paramater to the add...MessageText functions.

// texts.myTextId.text = "You cannot order && with &&"

// The first && will be replaced with the value of the myField Field
// The second && will be replaced with "caviar"
var substitutionArray = [fields.myField.value, "caviar"];

controls.myButton.addInfoMessage(texts.myTextId, substitutionArray);

// output: "You cannot order ketchup with caviar"

You can stop the execution of the rest of the event by setting the stopProcessing parameter to true e.g. controls.myControl.addErrorMessage("My message", true);

It is often more convinient to add the message to the owner of the event using event.owner.addErrorMessage("My message");

Steps


1

Create a new Form and add a Button Control.

2

Add a new On Click script to the Button Control with the following code:

event.owner.addInfoMessage("Button was clicked");
3

Run the Form and click the button. You will see a message appear.

4

Add a Field to your Form and name it clickCounter. Set the Field Type to Integer and give it a default value of 0.

5

Add a Linked Texts entity to your Project and include it in your Form.

Add a Text entry with the Id clickMessage with the string You have clicked the button && time(s).

6

Modify the button's On Click script to increment the clickCounter Field Value and to substitute it into the Info Message. Use the following code:

// Increment the clickCounter Field
fields.clickCounter.value++;

// Substitute in the counter to the message
event.owner.addInfoMessageText(texts.clickMessage, [fields.clickCounter.value]);

Current Module

Related