Search code examples
orbeon

Orbeon forms - repeated sub-section


I have repeated section (Minimum Number of Repetitions = 0; Maximum Number of Repetitions = 9). In this section it is nasted repeated sub-section (Minimum Number of Repetitions = 1; Maximum Number of Repetitions = 9). If I remove any repetition from section, then run Test and add first repetition to section, sub-section appears with no repetitions (although I have set Minimum Number of Repetitions to 1). Validator doesn't detect any error.

Is it possible to add repetition to sub-section, when I add repetition to section?

Probably I have to call sub-section template, when I add repetition to section: <xf:insert context="path_TODO" origin="instance('sub-section-template')"/>

but I don't know how and where I should call this. Maybe somewhere here: enter image description here

Example form: https://demo.orbeon.com/demo/fr/orbeon/builder/edit/81751a85c9206ee58ade5b1c16afeea6dc790327


Solution

  • In Form Builder:

    1. Add a first outer section, make it repeated; I'll call this the outer repeat.

    2. Inside the section, add the repeated grid; I'll call this the inner repeat.

    3. In the Section/Grid Settings for the repeated grid, check the box for Initial number of iterations uses template:

    4. Make sure you have 1 outer iteration, and 1 inner iteration:

    5. Edit the source of the form and add the following, just inside the <xf:model>:

       <fr:listener version="2018.2" modes="new" events="form-load-after-data"
                    actions="clear-outer-section"/>
       <fr:action name="clear-outer-section" version="2018.2">
           <fr:repeat-clear repeat="section-1"/>
       </fr:action>
      

    With step 1 to 4, when users create a new iteration of the outer repeat, the number of iterations in the inner repeat will be based on what you have in Form Builder in the first iteration of the outer repeat, instead of starting with 0 iteration. Your issue is that you want to have 0 outer iterations. But if you remove the last outer iteration, we don't have an example in the data for how many inner iterations to create. Hence we keep 1 in Form Builder, and remove it as soon as the form is loaded, which is what we do in step 5 with the action syntax.