Preview Surveys with Runtime Variables
Survey logic can depend on application data, such as a customer's plan or role. To test this logic, you can save sample values as named sets called variable presets. Use the selector at the bottom of Preview to switch between three customer profiles: "Basic member", "Premium member", and "Premium administrator". Click Manage presets to view, edit, add, or delete presets.
To configure presets, set the variablePresets property to an object with these properties:
definition
A survey JSON definition whose questions describe the variables. Question names identify variables, while question types, choices, and validators configure the preset editor. In this demo, a Dropdown question definescustomerTierand a Yes/No question definesisAccountAdmin.presets
An array of named variable presets. Each entry contains a uniquename, an optionaldescription, and avariablesobject that maps variable names to values.
Variables in survey expressions are referenced using curly brackets, just as question names. This demo uses "enableIf": "{customerTier} = 'premium'" to enable priority support and "visibleIf": "{isAccountAdmin} = true" to show the billing question. The variable definition also makes these variables available in visual condition editors.
Preset edits are kept in memory for the browser session. To save them, handle the onVariablePresetsChanged event and persist options.variablePresets when options.reason === "edit".
Refer to the Code tab for the complete survey and variable preset definitions.