Using Checkbox Select Question as a Repeat Count

Use Case Example

A partner is using a CommCare App to keep track of the different types of crops a farmer plants in their farm production. The app will keep track of the farmer’s details and the types of crops on their farm. The types of crops are selected from a checkbox dropdown list, and the number of selected crops determines the repeat count. Each repeat then collects information for each type of crop selected. The user is able to change their mind and deselect a crop.

Issue with Workflow

Deselecting an already selected crop results in the below error message. The cause of the error message is that it is not possible to directly delete a repeat without causing an error.

1.png

Steps to Resolve the Error

 

  1. Have a hidden value to calculate the current position of the repeat group starting from 0. The hidden value should be set to position(..)

    11.png

     

  2. Ensure that the repeat group has an inner group and place all of the inner contents of the repeat group inside that inner group

    1. Set the display condition of the inner group to position(..) < repeat_count_question (where repeat_count_question is the full path of the integer question that defines the repeat count)

  3. Ensure that every calculation referencing the checkbox question using the "selected-at" function does not perform any calculation if the count of selected items is zero. See the example below.

     

We have attached a sample XML form with an example below. You can download this and upload to your own test form.