Repeat Group deselection error

Hello,

I get this error upon deselection of an option within a question that triggers a repeat group.

This is my repeat group.

image

this is likely due to how commcare app doesn’t really remove repeats that are created.

so if you selected 4 items, and it created 4 repeats, and then you deselected 1 of the original 4 items, you’re still going to end up with 4 repeats.

i’d put a condition on the calculation that checks if the current repeat position is > = # of items selected

Thanks for the swift response. it’s strange that i have never had this problem with repeat groups in the past.

Would the calculation be in a hidden field? And where exactly do i place that, inside or outside of the repeat group?

image

inside crop to display

so in our example of selecting 4 crops and then changing that to 3, what’s hapening is this:

crop_based_questions[4] is trying to calculate crop_to_display. but there is not item at selected-at(crops, 4) so it throws an error.

if you do something like if (position(…) > count_selected_crops, 0, selected-at(etc…))
it will see that 4>3, and return a 0 instead of an error.

I am getting the error below

my code has 3 dots you likely need 2
position(…)

my memory is bad, can’t remember exact syntax to get position of current repeat

Even with two dots, it doesn’t work.

@Mazz,

This is the updated syntax but still throws an error when executing

i did something before where i made a hidden calculation that’s called “cur_position” inside the repeat
where the calculation was position(…) + 1
then where i needed to make a reference to the position, i did the condition like this
if(current()/…/cur_position > path_to_size_of_selected_items, 0"which means return false() and do nothing, perform a calculation)

HTH

GL

Mazz