Breakable Loop
A breakable loop allows respondents to repeat the same set of questions in a loop to add multiple entries. Respondents can exit the loop when they want to, or the loop can end automatically when a certain condition is met. This may happen when a maximum number of entries is reached, a specific value is entered, or a validation rule is triggered. Once the loop ends, the respondent can proceed to the next question or submit the survey.
In SurveyJS Form Library, two question types can be used to create a breakable loop: Dynamic Panel and Dynamic Matrix. Regardless of the question type you choose, the loop can be enabled only if your survey displays one input field per page. To enable this structure, set the questionsOnPageMode
property to "inputPerPage"
at the survey level.
To implement a breakable loop based on a Dynamic Panel or Dynamic Matrix, follow the steps below:
Configure the repeated questions.
Define the question configurations in thetemplateElements
array in a Dynamic Panel orcolumns
array in a Dynamic Matrix.Specify a title pattern.
Each iteration step displays a title. To customize it, use thetemplateTitle
property in a Dynamic Panel orsingleInputTitleTemplate
property in a Dynamic Matrix. The title pattern supports text piping from other questions and loop levels.(Optional) Define conditions for breaking the loop.
Respondents can stop adding new entries when they want to, but you can specify conditions that end the loop automatically. For example, themaxPanelCount
property in a Dynamic Panel andmaxRowCount
property in a Dynamic Matrix define the maximum number of repeating sections a user can add. This demo sets themaxPanelCount
property to 5. If you need a more sophisticated logic for breaking the loop, use triggers.
For a Dynamic Panel code example, refer to the Code tab in this demo. A Dynamic Matrix code example is shown in the Nested Loops demo.