Infinite loop and dynamically delete already selected options from list

Godd evening to all, hope everybody is ok.

I face a problem I can't resolve.
We drive a field servey of plants species inventory. Species list are different from on site to another (I use choice filter to manage it).
For the moment I builded my form in a non generic, hard to modify way : -> A select widget for the abundance of each species :scream:

Reading yesterday some great recipes on the forum, I tried and I achieved to merge two great ones from @LN and @jules_rugwiro :

and

So my colleagues can now loop in the species list until the select 'no more species' AND the previously select species get out of the list, so the can not count the same species two times.
This works really fine.

Now I want to include it into a bigger repeat group (lines 13 & 29 in the attached xls file)
indefinite_repeat_and_remove_already_selected_from_species_list.xlsx (10.8 KB)
This repeat group concern the locations visited on the field.

But when I try it I get a error from xlsformonline:

Error: ODK Validate Errors:

Something broke the parser. See above for a hint.
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
The following files failed validation:
${indefinite_repeat_and_remove_already_selected_from_species_list}.xml
Result: Invalid

I do not have any idea about the reason but I am not an xlsform guru :frowning:

I haven’t had a chance to look at your form yet but I’m guessing that you are trying to do this in a nested repeat, is that right? If so, you are running into a Collect bug that we hope to publish a fix for this week.

Yes exactly :grinning: A first repeat of geopoint and inside an infinite repeat for species.
Great to ear that it will probably work !
Now I remember I red something about this bug... but I am not sure... This will be a very useful form for us.

1 Like

May be I was too optimistic in my last message because I get the error when I try to transform the xls file into xml, not in colect...

Yes, that makes sense. The error is in JavaRosa which both use. We'll aim to publish a pyxform/XLSForm Online fix soon as well.

1 Like

Quick update here. We ended up doing a Collect point release without this fix because I noticed some problems with it and was pulled into other time-sensitive work. I hope to get back to it by the end of the week.

1 Like

Collect v1.26.3 is now out and should fix this issue.

However, I have since realized that the sample form can cause an infinite loop in Collect when using the hierarchy view or finalizing. To avoid this, you can change the count expression to add a check for blank values: ${count} = 0 or (${taxons_observes}[position()=${count}]/espece != '' and ${taxons_observes}[position()=${count}]/espece != 'maille_suivante'). I have updated the original sample form accordingly. Please give it a try and let us know how it works for you, @mathieubossaert!

1 Like

For the moment I still can't transform the xls to xml with XLSForm Online.

Ah, indeed, I had converted the form some weeks ago and forgot you'd run into that!

indefinite_repeat_and_remove_already_selected_from_species_list.xml (10.1 KB) is the XML I got by making the change described above and running the converter without the Validate step. I'll try to get XLSForm Online updated sooner than later.

2 Likes

Thanks @LN it works perfectly !

I spoke too fast.
The form logic is ok but I realized that the form has not been saved (Collect is still finalizing / saving the instance).

I have to kill Collect (1.26.3) and when I restart it, I am unable to load the form while the scrren freeze on "Loading"

:sob::sob::sob: Do you remember when I said that there was a change needed to the form design to make sure there wasn't an infinite loop on finalization? I sent you the converted form without making that change. So sorry about that.

Hopefully this one works better: indefinite_repeat_and_remove_already_selected_from_species_list.xml (10.2 KB)

1 Like

Works great. Thanks @LN :grinning:

I am facing a problem with this form. I am preparing the 2022 field season and I would like to use this generic form, as the number of species and sites is now too big to use a none generic way.
On the collect side, the form is well finalized at the end of data collection (as I said in the last message).
I try it today and go forward with submissions. And I realize that species code (select_one especes) is empty.

I can't understand why so I think it could be a bug ?

Here are the form and submission data archive
suivi_maille_generique.xlsx (14.1 KB)
suivi_maille_generique.csv-3.zip (1.5 KB)

It is quite weird, when I add a calculate field containing ${espece} this calculation is ok and this field is well submitted to Central, but select_one still empty.

suivi_maille_generique.xlsx (14.1 KB)

Thanks to @LN I managed to get it work :

Here is the final form !
suivi_maille_generique.xlsx (14,2 Ko)
Edit : because I forgot to "unhide" the geopint question :wink:

1 Like

Hi !
I found another solution to do that trick ! The main idea is to concat the current choice (Q1) with an unique id (position(..)) (Q0) in order to compare the current selection of a repeat group and the other ones (C1). The choice_filter exludes the current selection (Q1) from the list (C1) with the functions substring-before and substring-after. Then, it only check if the name was already selected or not.

By using the functions substring-before and substring-after, we are able to edit previous selections without any duplication.

This is the trick (working on Kobo Collect and Enketo) :

survey :

choices :
C2

I hope it will help someone. See you :slight_smile:

William

Hi,
The previous solution worked only for name values with the same length or really differents (for example the values "on" and "one" would not have worked). This another version is working with a concatenation of a special character ('#' in red). It's not exhaustive but for me... it's enough ! You can of course extand the character with a unique sequence ('#$^%ù~ [...] +=').

survey

It could be great to limit the number of repetition with the size of Q1 list. Any idea to achieve it ?

Looking to get your feedback :slight_smile:

See you,
William

Thanks @willydauphin and welcome to the ODK community forum ! When you get a chance, please take some time to introduce yourself here :wink:
Thanks for sharing, I will try it with Collect. Lazy question : could you share an xlsform ?

You might take a look at this discussion and the proposed trick

Thanks @mathieubossaert for your reply !

Yes I can share xlsform !

Solution :
test_choice_filter.xlsx (13.6 KB)

Solution (with a "dynamic" repeat-count, according to this) :
test_choice_filter_with_limit.xlsx (13.8 KB)

Unfortunately, I'm wondering if it's possible to limit the number of repetitions. With the second form, I only fix the number of repetitions. I would like to have someting like '.<${Q1_length}' but it looks like impossible or seems to be a very bad way. Any idea ?

Thanks again :slight_smile: