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.
To create such a dynamic field, you need to:
- Create arrays that return the required data sets for the options that will be available for selection.
- Define a function that chooses one of the arrays depending on the defined condition.
- Create a Single Selection field with the "Use Choices Expression" setting selected.
- In the Choices Expression setting, call the predefined JavaScript function.
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.
Step | Result | |
---|---|---|
1 | To find out what meta field names and corresponding values to use, so that they map correctly to a PDF form, open a relevant document from a Client subfolder. Turn on Admin Mode, by clicking the cogwheel icon . Meta field names and their values can be seen by floating the mouse cursor over a field. | Meta Field Names and Values on a PDF form in Admin Mode |
2 | Proceed to Administration menu > Single Pane of Glass tile > Widgets tile and create a new Dynamic Wizard widget. | |
3 | Open the Docupace Start editor and navigate to Wizard tab > Wizard Settings. | |
4 | In the onLoad actions section add new JS code. | |
Field | Value | |
5 | Virtual file name |
|
6 | Code This script first defines a Then it defines a If there is no value selected, then this dropdown will also be empty. If there is a value selected, then it checks whether the value matches one of the cases defined here, and shows the corresponding options:
As the values are "hard-coded" in this script, make sure they match exactly those values, which will be available to the user in the Investment Objective field. In this case, they are choices defined directly in the Investment Objectives field. | $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 [] } } |
7 | Open the Pages tab, create a new page and proceed to add two fields to it. | |
8 | Open Add Field panel. Add a Checkbox Section field to the page. This first field will ask the user to answer the question: Is Income Your Account Investment Objective? Enter the following values for the field settings: | |
Field | Value | |
9 | Field Label |
This is the name of the field that is displayed to the user. |
10 | Meta Field Name |
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. |
11 | Initial value |
As "3" is the value for a deselected checkbox, then the checkbox will initially be deselect, but it's value will not be NULL. |
12 | Value for Checked | 1 This value will map to the corresponding "value" attributes of the meta field name in the PDF form, if the checkbox is selected. |
13 | Value for Not Checked |
This value will map to the corresponding "value" attributes of the meta field name in the PDF form, if the checkbox is not selected. |
14 | Open Add Field panel. Add a Single Selection field to the page. This second field will show Risk Tolerance options, applicable to the selected investment objective. Enter the following values for the field settings: | Adding a Single Selection field |
Field | Value | |
15 | Field Label |
This is the name of the field that is displayed above the list of options. |
16 | Use label as placeholder | Selected |
17 | Meta Field Name |
This is the unique name for the data held within the field as it will be mapped to respective fields in PDF forms. |
18 | Display Type | Radio List The list of options will be displayed as radio buttons. |
19 | Layout | Horizontal The radio buttons will be displayed horizontally. |
20 | Use choices expression | Selected |
21 | Choices expression | This will call the If your fields are located within a Field Group, then use |
22 | Click Apply button in the bottom of the screen to close the Widget Design Screen and apply changes. Then click Save button in the top of the Widget Details Screen to save these changes. | |
23 | 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 |