Loop and Merge
Loop and Merge is a feature that allows you to repeat a group of questions and combine the responses into one data object. The loop can either iterate over the same set of questions for each item or adjust dynamically based on user input. In this example, you can select one or multiple SurveyJS products, and the survey will then ask a series of repeating questions about each selected product.
Supported Question Types
A question loop can be created using one of the complex question types:
Single- and Multi-Select Matrices produce a predefined number of loops—one for each matrix row. In contrast, Dynamic Matrix and Dynamic Panel types allow users to add new entries during the survey, generating new loops on the fly.
Configure the Loop
Loop and Merge requires the survey structure to change and display only one input field per survey page. To enable this structure, set the questionsOnPageMode
property to "inputPerPage"
at the survey level.
If you are implementing a loop based on a matrix, the matrix rows represent items, and the columns represent the questions to iterate over. You can manage which loops are included or excluded by controlling row visibility with the rowsVisibleIf
expression. In this demo, we use the rowsVisibleIf
expression to filter out unselected SurveyJS products.
Each loop step also displays a view title. In Multi-Select and Dynamic Matrices, you can customize the title using the singleInputTitleTemplate
property. This property supports dynamic placeholders ({rowIndex}
, {rowName}
, and {rowTitle}
) and text piping from neighboring matrix cells and other questions.
If you are using a Dynamic Panel for the loop, define the set of questions to repeat inside the panel template. Refer to the following example for more details: Breakable Loop.