1. Navigation

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:

<? register event @OnClick ?>
<button class="btn btn-default" onclick="<?attr @OnClick ?>">Click me</button>

Next, add a dropdown property called "Action" with the following options:

Label
Value

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:

if @Action = "execute"
	execute @Flowchart
elseif @Action = "navigate" 
	navigate to @NavigationItem
elseif @Action = "follow" 
	follow @ButtonExit
end

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.

Was this helpful?