Can I select 5 Choices, and then the repeat loop happens only for those 5

Hello,

New Question, Same form, is there a way that I can make a choice of say 3 out of 10 things, and then the nested repeat loop happens only for those 3 things.

e.g. I have to collect information by team in different classrooms, some classrooms will have 3 teams, some will have 10 . Is there a way that before the repeat starts, the teacher chooses Teams (which are standard named as Team 1, Team 2 .....) and then the repeat function happens only for that chosen list ?

if the nested repeat information are same and repeat creates based on a multiple selection item then you can use this xls idea.multiple_selected_item_repeat.xlsx (14.7 KB)

1 Like

Thanks a lot. I will try running the file you have shared. Would you be able help me understand what does the jr. function do?

Jr:Count ....

count-selected(${item}) - you put this twice, once under Jr:Count and once under Repeat_Count . Could you help me understand why?

By the time I am here, I am at the sea :slight_smile: . If I can help understand the logics, i will probably be able to use it multiple contexts -

selected-at(${item}, position(..)-1)
jr:choice-name(${item_post}, '${item}')

I am sorry, I am clearly far too novice. I am not able to see how to use this or modify it to run it on the phone once to see what this logic would look like etc.

To learn XLS form authoring you can check the documents:

https://docs.opendatakit.org/form-question-types/

2 Likes

Nothing beats a good example to plagiarize... :wink:

selectrepeat.xls (19.5 KB)

Try running this under XLSForm Online to see how all these pieces fit together. You should be able to adapt to your specific need. Also check the online docs for count-selected(), selected-at(), jr:choice-name() and repeat_count

2 Likes

Each one of you here is a gift from the universe!! Thanks so much :).

I just used the logic you have provided, it was shared by another kind person on another group. I somehow seem to be getting the First Team Name on all repeat sheets.

Row 34, 35 is where I set the logic calculations and 36 is where the note drops.

Row 29 is where they choose the teams.

What am I doing wrong here? On both the examples, they work on my phone, my own sheet somehow throws up the same team name of Team-A

inquilab-introduction-activity-form-3.xlsx (17.9 KB)

OK. So the 'problem' you are witnessing in your form is a consequence of the fact that you have an inner group within your repeat group, inside of which you are using selected-at(). As a consequence, when you perform

selected-at(${fruit}, position(..)-1)

the '..' is basically jumping up one group level to figure out which iteration it is in. Normally, that is when you are directly inside a repeat group, this corresponds to the repeat iteration (1,2,3,4...). However, because you are using it within a (single) inner group, position(..) is always going to return 1 (!). Hence why you keep getting that dang First Team Name! :smile:

The workaround in your case is to jump up another level so that the position() function actually gets the correct iteration that you are in; that is

selected-at(${fruit}, position(../..)-1)

OK. I realize this might be getting a bit over your head, but dont worry! :slight_smile: We're getting pretty down-n-dirty into obscure XPath stuff here, but it is probably worth explicitly documenting in case other's fall into your same trap (@ln?):

if you try to use position(..) - to find out what iteration your are in - you must be immediately within the encompassing repeat group, otherwise you'll get an invalid index (probably always 1...)

To answer your immediate problem, try this form instead, which - like yours - has a group within a repeat group:

selectrepeat2.xls (20 KB)

3 Likes

Thank you @Xiphware : This explanation completely helps. Thanks so much for everything !!! :slight_smile:

2 Likes

Thanks a lot it's very helpful :slight_smile:

1 Like