Model Iteration inside a Question List/Checkbox

Dear All,
I have completed this idea into a project
https://wiki.commcarehq.org/display/commcarepublic/Using+Repeat+Groups+in+the+Form+Builder
But it brings all the options from the Lookup Table when the questions are repeated, but I want to repeat the questions when choosing the option from the Lookup Table (as in the image)
When I chose "Flopsy" in the Lookup Table the repeat group give me a repetitive value in the name of "Flopsy" in the hidden question "bunny"
For note, I make "bunnies" in Lookup Table
Best regards,
Ahmed

version 1
id	type	labelItext:en-default	appearance	calculateAttr	defaultValue	instances	itemsetData	rawDataAttributes	rawRepeatAttributes	repeat_count
/repeat_count	DataBindOnly	null	null	null	count(instance('bunnies')/bunnies_list/bunnies)	"{""bunnies"":{""src"":""jr://fixture/item-list:bunnies""}}"	null	null	null	null
/bunnies	MSelectDynamic	Bunnies	null	null	null	"{""bunnies"":{""src"":""jr://fixture/item-list:bunnies""}}"	"[{""instance"":{""src"":""jr://fixture/item-list:bunnies"",""id"":""bunnies""},""nodeset"":""instance('bunnies')/bunnies_list/bunnies"",""valueRef"":""name"",""labelRef"":""name""}]"	null	null	null
/qustion_list	FieldList	repeat_group	field-list	null	null	null	null	null	null	null
/qustion_list/repeat_group	Repeat	repeat group	null	null	null	null	null	"{""jr:template"":""""}"	"{""jr:noAddRemove"":""true()""}"	#form/repeat_count
/qustion_list/repeat_group/position	DataBindOnly	null	null	position(..) + 1	null	null	null	null	null	null
/qustion_list/repeat_group/bunny	DataBindOnly	null	null	instance('bunnies')/bunnies_list/bunnies[current()/../position]/name	null	"{""bunnies"":{""src"":""jr://fixture/item-list:bunnies""}}"	null	null	null	null
/qustion_list/repeat_group/bunny_label	Trigger	"<output value=""current()/../position"" /> - <output value=""current()/../bunny"" />"	minimal	null	null	null	null	null	null	null

Hi,

You copied what was in the tutoriel, but the exemple in the tutoriel does not act as you want it...
Your repeat count is counting the number of bunnies insid your lookup table. You need to count the number of bunnies you have selected.
You need to change the bunny hidden value inside your repeat group to link to your multiple choice question instead of the lookup table.

I haven't tested it, but something like that :

version 1
id	type	labelItext:en-default	appearance	calculateAttr	defaultValue	instances	itemsetData	rawDataAttributes	rawRepeatAttributes	repeat_count
/repeat_count	DataBindOnly	null	null	null	count-selected(#form/bunnies)	{"bunnies":{"src":"jr://fixture/item-list:bunnies"}}	null	null	null	null
/bunnies	MSelectDynamic	Bunnies	null	null	null	{"bunnies":{"src":"jr://fixture/item-list:bunnies"}}	[{"instance":{"src":"jr://fixture/item-list:bunnies","id":"bunnies"},"nodeset":"instance('bunnies')/bunnies_list/bunnies","valueRef":"name","labelRef":"name"}]	null	null	null
/qustion_list	FieldList	repeat_group	field-list	null	null	null	null	null	null	null
/qustion_list/repeat_group	Repeat	repeat group	null	null	null	null	null	{"jr:template":""}	{"jr:noAddRemove":"true()"}	#form/repeat_count
/qustion_list/repeat_group/position	DataBindOnly	null	null	position(..) + 1	null	null	null	null	null	null
/qustion_list/repeat_group/bunny	DataBindOnly	null	null	selected-at(#form/bunnies, current()/../position-1)	null	{"bunnies":{"src":"jr://fixture/item-list:bunnies"}}	null	null	null	null
/qustion_list/repeat_group/bunny_label	Trigger	<output value="current()/../position" /> - <output value="current()/../bunny" />	minimal	null	null	null	null	null	null	null

-Michel

Dear Michel,

Thank you for replay,
I tested it in other FORM, but it didn't work as in the image

I try to put >>count-selected(#form/bunnies) << in the Calculate Condition, it is working but the repeat group doesn't work as in the image:

Thank you again,
Ahmed

Hi,

The second option is the one valid. The calculation has to be in the calculate condition field.

But the bug lies elsewhere : inside the repeat group, for the calculation of the bunny hidden value, try putting some spaces after 'position' like that :

selected-at(#form/bunnies, current()/../position - 1)

-Michel

Dear Michel,

it is Working thank you a lot.
I appreciation for your follow-up
But, when I back to select and I cancel one choice from (bunnies) it gives me an error as in the Image in below.
in fact, I trayed to do some change in repeat group as in the CommCare tutorial as this [Remove repeat Group] (Using Repeat Groups in the Form Builder - CommCare Public - CommCare Public)
but it didn't work as in the image

`count(#form/repeat_group)`

#form/counter + 1
Can I ask you for help by adding another selection (like "items" ) and combining it with the first option (bunnies) to be repeated during repetition in Repeat Group?
I tried but it didn't work I put:
selected-at(#form/bunnies, current()/../position - 1) or selected-at(#form/items, current()/../position - 1)

Please find my example:
Form Builder clip version 1
id type labelItext:en-default appearance calculateAttr rawDataAttributes rawRepeatAttributes repeat_count
/repeat_count DataBindOnly null null #form/items_collect + #form/bunnies_collect null null null
/items_collect DataBindOnly null null count-selected(#form/items) null null null
/bunnies_collect DataBindOnly null null count-selected(#form/bunnies) null null null
/copy-1-of-repeat_count Trigger "<output value=""#form/repeat_count"" />

<output value=""#form/items_collect"" /> 

<output value=""#form/bunnies_collect"" /> "	minimal	null	null	null	null
/items	MSelect	Items	null	null	null	null	null
/items/Wood	Choice	Wood	null	null	null	null	null
/items/stee	Choice	Stee	null	null	null	null	null
/items/glass	Choice	glass	null	null	null	null	null
/bunnies	MSelect	bunnies	null	null	null	null	null
/bunnies/flopsy	Choice	Flopsy	null	null	null	null	null
/bunnies/mopsy	Choice	Mopsy	null	null	null	null	null
/bunnies/cottontail	Choice	Cottontail	null	null	null	null	null
/qustion_list	FieldList	repeat_group	field-list	null	null	null	null
/qustion_list/repeat_group	Repeat	repeat group	null	null	"{""jr:template"":""""}"	"{""jr:noAddRemove"":""true()""}"	#form/repeat_count
/qustion_list/repeat_group/position	DataBindOnly	null	null	position(..) + 1	null	null	null
/qustion_list/repeat_group/bunny	DataBindOnly	null	null	selected-at(#form/bunnies, current()/../position - 1) or selected-at(#form/items, current()/../position - 1)	null	null	null
/qustion_list/repeat_group/bunny_label	Trigger	"<output value=""current()/../position"" /> - <output value=""current()/../bunny"" />"	minimal	null	null	null	null

To clear that error, change the expression to :
if(#form/bunnies = '', '', selected-at(#form/bunnies, current()/../position - 1))

The idea is not to run selected-at() when #form/bunnies is empty or null(which happens when you deselect all items in the list)