Occasionally, you'll need to create a form with a variable number of form elements. In my case, I needed to allow the user to define a survey with text fields, text areas, checkboxes and select lists. To solve this, I created a Panel for each element type: TextFieldPanel, TextAreaPanel, etc.

When the form is created, I add each element Panel to a ListView, which is then iterated over in the markup.
The ListView has to use optimizedItemRemovel (see: Using listviews) or form components will forget their content.

I use the same process when I render the survey to the user filling in the survey. I just needed to create a new set of Panels.

See also: Create dynamic markup hierarchies using panels
See also: Page with dynamic components

  • No labels