In previous chapters, we used events to refresh the page without writing any code for it, and to toggle between the collapsed and expanded states of our message box widget. In this chapter, we will create our own button and add different types of actions to it.
First, create a new widget and name it "Button." Use the following script:
Next, add a dropdown property called "Action" with the following options:
Refresh screen
refresh
Execute flowchart
execute
Navigate to
navigate
Follow button exit
follow
Then, add three additional properties called "Flowchart," "NavigationItem," and "ButtonExit," using the same property type as their names. Do you remember the "Visible when" property explained previously? Click on the "ButtonExit" property and change the "Visible when" setting from "Always visible" to "Action." Note that "Action" refers to the dropdown property we created with selectable options. For "ButtonExit," check the "follow" checkbox. Repeat this process for the other two properties. You will see this functionality in action once we display this widget in the template editor.
Now, create an event called "OnClick" and use the following example code:
Three new statements are introduced here: execute
, navigate
, and follow
. By now, you should be familiar with WEM terminology. If you read the code, you will find that these statements do exactly what you expect, and they should be self-explanatory.
Events also allow for the manipulation of the row position within a list. This functionality is similar to using the List node in the flowchart editor; however, not all features available in the List node are supported.
The basic syntax is as follows:
The syntax is straightforward, so we won't go into detail about what each command does. However, as mentioned earlier, not every feature is available out of the box. For instance, if we want to create an event that navigates to a specific row, we can program it as follows: we create a numeric view state called "RowIndex" to store the current row index. Note that in this example, the indices start at 1, with the first row being index 1. Fortunately, the code is quite simple: