Expressions in Dynamic Panel
Expressions let you configure conditional logic to create dynamic surveys. You can use expressions to implement branching and skip logic, dynamically show and hide questions, mark them as required, enable and disable them, and perform calculations right in the survey JSON schema. This example demonstrates expressions in a Dynamic Panel. Here expressions are used to calculate employment duration. Enter a company name and employment dates to see the number of days employed for this company. You can add as many companies as you want—days employed will be added up and displayed under the Dynamic Panel.
Access Questions Within a Panel
To reference questions within the same panel in your expressions, use the panel
prefix as follows: {panel.questionName}
. Refer to the expressions within the Employment History panel for code examples.
Dynamically Calculate Values
Expressions support built-in functions and allow you to create custom functions for in-survey calculations. In this demo, expressions calculate the number of days employed using built-in diffDays
and sumInArray
functions. For more information on how to use these and other built-in functions or how to implement a custom function, refer to the Expressions help topic.
Manage Question Visibility
You can use expressions to implement conditional visibility for questions, choice options, matrix columns/rows, and other elements. In this demo, the number of days for individual companies is only displayed when you enter both the company name and employment dates. To implement this functionality, assign a Boolean expression to the visibleIf
property. You can find more details in the Conditional Visibility help topic.
Validate Question Values
Expressions can be used to add data validation to your survey. In this example, the Employment Dates question fields use the minValueExpression
and maxValueExpression
properties to ensure that the end date falls within the range between the selected start date and the current date. For more information about data validation in SurveyJS Form Library, refer to the following help topic: Data Validation.