Dynamic choice list in select_one_from_file based on total selection in previous repeat cycle

Hey everyone,

I’ve been stuck several days with the same problem now. I’ve looked around a lot in the forum and found similar issues, but nothing quite like what I’m trying to do, and nothing that has helped me solve my problem so far. Hopefully some of you out there have some good ideas on his this might be solved! :slight_smile:

Basically, I’m designing a data collection form for a vegetation survey. In the first part of the form, I have a repeat cycle where I want the user to register all the plant species existing at a certain site (using select_one_from_file and referring to an complete species_list.csv of several thousand species). In the second part of the form, I want the user to estimate the cover of each registered species. The two important parts here is that (1) the user gets presented with only the species that have been registered in the first step and that (2) the user can select which order to provide the cover estimations for the species.

My idea was to add another (“cover est.”) repeat cycle with a repeat_count equal to the number of repeats in the first (“registration”) repeat cycle and adding a choice_filter for the species selected across all repeats in the first select_one_from_file row. I tried doing this by “calculating” all_registered_species in different ways (I tried using join(), selected-at(), concat(), indexed_repeat()) and then referencing that calculation either in the choice_filter cell or directly in the select_one_from_file cell. So far, I’ve always encountered one of two problems: Either the registered species don’t show up as selectable options at all in the “registration” repeat cycle, or they show up concatenated as one single option (i.e., I may register three species, but in the second repeat cycle, I see only one option, but it’s called “Species 1 Species 2 Species 3”).

If someone has any idea of how my problem can be solved, or if I can tackle it in a different way, I would be really grateful for all good input! As a new user, I’m afraid I can’t upload attachments, otherwise I’d be more than happy to provide an example of my form and csv-file for added clarity.

Thanks! :shamrock:
Albin

How critical is point (2)? That is, the user must be able to select to order of species to respond to?

Point (1) isnt hard.

Point (2) is hard, and may in fact not be currently possible.

1 Like

Thanks for your reply! In short, it’s definitely important and I would much prefer finding a solution that allows for both point (1) and (2) to be implemented (unless it’s actually impossible …).

Please add if you have other thoughts, but I guess point (1) is simple in that you could create a repeat cycle with e.g., a decimal row where you refer to the selected answer in that indexed version of the previous (registration) repeat cycle and simply make the species appear in the same order as they were registered? One possibility I thought of was to do exactly this, but then displaying the decimal rows from all repeats of the repeat cycle on the same page, so the user could still select which species to begin with. But then I found out there’s no way to display all repeats of a repeat cycle on one page. That’s why I started considering a select_one_from_file but filtered for registered species in the second repeat cycle as well. But obviously, I’m struggling with that as well…

Cheers!

I understand this, but what I dont understand is why you would be acquiring this data via a repeat loop with a single select_one; why not use a simple select_multiple? Then, follow it with a repeat that iterates thru all the selected species and ask additional question(s) about each (eg coverage).

Have a look at the following form which implements this workflow. I dont know what you have/not got working so far, but it is probably nonetheless important that you understand how this this simple select/repeat example works, even if you don’t end up using it directly. It covers a lot of the form design elements you may need:

RepeatFromSelect.xlsx (18.5 KB)

This form uses a select multiple to select a subset of items from a list of all (fruit), then for each one selected it asks a followup question. Replace fruit with your species, and “how many?” with “coverage”, and it would seem to accomplish something very similar to what you are trying to do. Obviously, however, the order of fruit presented in the followup repeat is predetermined by the order they appear in the favorites list, over which you have no control. My simple example also uses an in-form choice list, not an external csv, but that it largely ancillary.

1 Like

Thanks for your feedback! So the reason why I’m using a “select_one” and a repeat cycle for the species registration instead of a “select_multiple” is that I want the user to insert some information about each registered species as it gets registered (e.g., is the species flowering? where in the plot was it found?). I realize the design of my form could be made simpler if I used a select_multiple instead, but I’m basically trying to re-create the workflow of an already-existing vegetation survey protocol.

I’ve uploaded an example of my form here below. As you can see, in my example I’ve incorporated three calculate-rows to combine and calculate the total species selected throughout the first repeat group (called “c3” in my example) using the method described in the following topic: “Restrict choices already selected from a repeat group”. I then use “c3” (or the total registered species) to (1) calculate how many times the next repeat cycle should be repeated, to (2) show the user which species have been register so far in the first repeat cycle, and (3) try create a choice_list of which species out of the complete species_list were selected in the first repeat cycle so that only these species are displayed in the second select_one. In my example, I’ve also changed the form to use an internal “example species list”, but in the final form, I’d list to refer to an external csv-list instead.

As of now, I get an error message trying to validate this form at (ODK - XLSForm Online) referring to the c3-row, but when I upload the form on kobotoolbox.org, I don’t get the error message. The first two uses of the “c3” calculate row (i.e., calculate number of repeat cycles, and display selected species) work fine. But the choice list does not work. Now, no options whatsoever are displayed in the “select_one” section of the second repeat cycle. As I mentioned in my initial topic thread, I’ve played around with this a bit and also tried e.g., creating a choice_list using join() instead of selected-at() where the registered species were actually displayed in the second “select_one” section, but then only as a long concatenated text string (i.e. “Species1 Species2 Species3”) and not as different options that could be selected.

Cheers!
Albin

vegetation_survey.xlsx (11.1 KB)





Understood. You want the user to be able to enter some details immediately upon their selection, but then also permit them to add further details later (for each selected).

Have a look at my following form; I think it accomplishes your need. It is quite a bit trickier than the basic select_multiple. You can ignore the choice_filter initially, as that doesn’t fundamentally affect the workflow itself. However, I think it is probably desired to prevent the user from re-selecting previously selected items [actually, getting this choice_filter right took most of the effort… :sweat:]


RepeatWithFollowup.xlsx (10.6 KB)

As you can see, initially it uses a repeat against a select_one to acquire all your species/fruit. It then has another repeat loop to iterate thru this list, asking for further details. Again, as before, you cannot control the order they are presented in the second loop (I still don’t know how/if that might be possible…).

Note, each subsequent select_one removes any previous selected options from the list.

Have a play and let me know what you think. It is actually an interesting and potentially useful workflow elsewhere :+1:. Tested against Enketo and KoboCollect.

1 Like

Thanks for all your help and feedback Xiphware! And yes, aside from allowing me to select which order to input further information about the fruits in the second repeat (sorry to hear that might not be possible as of now…), your form otherwise does everything I need it to do. Thanks again - I might keep thinking and playing with this form a bit and if I come across any new hurdles or realizations, I’ll write an update here.

Thanks again!
Albin

Actually, I’d like to add an additional question here, in reference to this thread:

Is it possible to create a select_one type question where the choices are all the names entered in a previous repeat group question? - User Support / Form Building - KoboToolbox Community Forum }

In this topic, there’s a simple form for creating a “select_one” referring to another “select_one” in a previous “repeat_group” and the second “select_one” displays only the options that were selected throughout all repeats of the repeat_group. The form provided in that topic works perfectly, and I’m thinking that could also solve my problem as explained here above (if I choose to use an internal species list instead), where I want two repeat groups - one for entering details immediately, and one for further details later on - and I want to chose the order of input for the further details in the second repeat group (which you described as might not be possible as of now, Xiphware). I thought I could adopt the form from this topic and just add the Q3 (the second select_one row) inside another repeat group. But, as soon as I do that, the options to select between disappear completely from the view, although I get no error message validating it in Enketo. I’m wondering - is this a bug? Have I misinterpreted how this is supposed to work, or forgotten some restriction? Might there be a way to solve the challenge I’ve described here using this approach?

I’ve attached the two forms (the functional [form1-working] and the non-functional [form2-not-working]) together with some screenshots. The choice tab is the same for both forms.

form1_working.xlsx (11.1 KB)
form2_not-working.xlsx (11.2 KB)





Nice try! You are correct in that you can ‘harvest’ the previously selected options using values entered in a repeat, as described here: Generating select ones from repeats.

Indeed, this would appear to be the best (only?) approach. And to be frank, I dont know why it is works entirely as designed in your first form, but not in your second form when the select happens to now be inside another repeat… :thinking:

What is interesting is that it does in fact work - exactly as desired - if you run the same form in KoboCollect (!)

So your approach seems to be valid. But I dont know why Enketo is (mis)behaving differently. :confused: And whatever the underlying issue is, it is probably not going to be trivial to address. :slightly_frowning_face:

Hahaha, well the fact that it’s working in KoboCollect is already something - I didn’t even realize that! I’ll see if I keep working with the earlier solution you suggested or this second half-validated solution, or maybe both parallel to each other and see what works best for me. Thanks again @Xiphware for all your help!