Bind Widgets’ Values to Variables
As an application designer or story developer, you can bind some simple widgets' values to variables like script variables, model variables, tile variables (widget-level variables) and analytic application or story properties so that the values can be updated automatically. The other way around, by binding you can enable writing the value set for a simple widget in view time back to a certain variable and applying the variable wherever needed.
The simple widgets and corresponding variable types available for binding are:
- list box, dropdown, checkbox group and radio button group
Their ID and display text can be bound to script variables, model variables or tile variables.
- input field and text area
Their display text can be bound to script variables, model variables, tile variables or analytic application or story properties.
When the variable is an array, the values displayed will be separated by commas.
- slider and range slider
Slider’s current value and range slider’s start and end values can be bound to script variables, model variables or tile variables. The variables must be single values of the number type.
- image
It can be bound to a script variable. The variable must be single value of the string type.
Image only supports such binding when dynamically setting image URL is enabled.
The analytic application or story properties include current user, time or date, last modified date or date/time, last modifier and creator.
In general, if not specified, the variables available for binding are primitive type variables (string, boolean, integer or number) and can be array or single value.
Push, pop or index of array in scripting won’t be reflected in the bound widget.
Align the type of widget’s value with the write-back script variable.
Example 1: Synchronize a Slider’s Current Value with a Chart’s Variable
Say you want to synchronize Slider_1’s current value with a script variable used in Chart_1, Variable_1.
-
Go to the Builder panel of Slider_1.
-
Under Data Source Type, select Script Variables from the dropdown list.
-
Under Current Value, select Variable_1 from the dropdown list.
-
Save the analytic application or story.
In view time, select (Edit Chart Prompts) in Chart_1 and adjust the value of Variable_1.
Slider_1's value will be changed accordingly.
Example 2: Use a Slider’s Current Value as the Threshold of a Chart’s Conditional Formatting
Say you want to use Slider_1’s current value that end users select in runtime as the threshold of Chart_1’s conditional formatting.
-
Create a number type variable Variable_2.
-
Go to the Builder panel of Slider_1.
-
In Slider Properties, turn on Enable the write-back in runtime.
-
Under Write current value back to the variable, select Variable_2 from the dropdown list.
-
Go to the Builder panel of Chart_1.
-
Select (Threshold Options) beside the measure you want to apply conditional formatting to and then Edit Ranges….
-
Configure the threshold. Under Comparison Measure, select Variable_2.
Current value of the slider is automatically written back to the variable applied to the chart’s conditional formatting. The threshold of Chart_1 will always take the current value of Slider_1.
If end user changes such a widget’s value directly or via API at runtime while you’ve defined a variable bound to this widget’s value at design time, the variable binding will become invalid.