Space TimelineSpace Timeline

Creating a Dynamic Selection Using Choices Expressions

Click on Images to Expand Them

Choices Expressions are used to create selection lists (dropdowns, radio button lists, or choice buttons) with dynamically changing values. That means the list of options will be different depending on some condition. This condition can be based on a value selected in another field; permissions of the user; account owner's age; the number of listed beneficiaries; etc.

In the example below, options for Risk Tolerance will be restricted by the user's answer to the Is Income Your Account Investment Objective? question. The question will be a Checkbox Selection field with two pre-defined choices. The Risk Tolerance will be a Single Selection field that uses Choices Expressions and is displayed as a list of Radio Buttons.

To create such a dynamic field, you need to:

  1. Create arrays that return the required data sets for the options that will be available for selection.

  2. Define a function that chooses one of the arrays depending on the defined condition.

  3. Create a Single Selection field with the "Use Choices Expression" setting selected.

  4. In the Choices Expression setting, call the predefined JavaScript function.

Step 1: Find Meta Field Names and Values.

This is important for mapping fields correctly to a PDF form.

Meta Field Names and Values on a PDF form in Admin Mode

Step 2: Create a New Widget.

Step 3: Add a Load Action.

Field

Value

Field

Value

Virtual file name

dynamicDropdowns.js

Code

$scope.dspSession = {} $scope.dspSession.getRiskToleranceOptions = function getRiskToleranceOptions(portfolioObjective) { if (portfolioObjective == null) { return [] } switch (portfolioObjective) { case '1': //'Income' return [ { value: '1', label: 'Low' }, { value: '2', label: 'Moderate' } ] break case '3': //'All Options' return [ { value: '1', label: 'Low' }, { value: '2', label: 'Moderate' }, { value: '4', label: 'Speculation' }, { value: '3', label: 'High Risk' } ] break default: return [] } }

Step 4: Create a New Page

Step 5: Add a Checkbox Section Field.

Adding a Checkbox Section field

Value

 

Value

 

Is Income Your Account Investment Objective?

This is the name of the field that is displayed to the user.

Owner1.PortfolioObj

This is the unique name for the data held within the field as it will be referenced by other JavaScript code in the widget (the Choices Expressions function defined earlier) and mapped to respective fields in PDF forms.

"3"

As "3" is the value for a deselected checkbox, then the checkbox will initially be deselected, but its value will not be NULL.

1

This value will map to the corresponding "value" attributes of the meta field name in the PDF form if the checkbox is selected.

3

This value will map to the corresponding "value" attributes of the meta field name in the PDF form if the checkbox is not selected.

Step 6: Add a Single Selection Field.

Adding a Single Selection field

Field

Value

 

Field

Value

 

Field Label

Risk Tolerance

This is the name of the field that is displayed above the list of options.

Use label as placeholder

Selected

 

Meta Field Name

Owner1.RiskTolerance

This is the unique name for the data held within the field as it will be mapped to respective fields in PDF forms.

Display Type

Radio List

The list of options will be displayed as radio buttons.

Layout

Horizontal

The radio buttons will be displayed horizontally.

Use choices expression

Selected

 

Choices expression

This will call the getRiskToleranceOptions function and pass to it the value selected in the Owner1.PortfolioObj field.

Alternate: If your fields are located within a Field Group, then use 'model.parent.value' instead of 'startingPointData' to refer the checkbox field.

Step 7: Apply Your Changes.

Step 8: Test Your Widget.

Test the widget. For example, by selecting 'Is Income Your Account Investment Objective?' option in the wizard. Available options for the Risk Tolerance field should be reduced to two options 'Low' and 'Moderate'.

List of options changes based on a checkbox selection