Filtering in a repeated field and exiting in a repeated field befor the end

Hi I have two questions :
1- I have a repeat field with a select_one and I want the option allready selctead not appear in the next repetions.
2- Is there any way tp stop a repetition wile I have not reach the maximum fixed number in repeat_count ?

Hello~

For (1), for the choice_filter of that question, you will want to use indexed-repeat() to refer to the previous repeat instance (position(..) -).

I cannot remember off the top of my head if this will produce an error on the first instance of the repeat, since the choice filter would be referencing a repeat that does not exist. If that's the case, you will have to either (a) add some code to the choice filter to nullify it if it is the first repeat instance, or (b) have a one version of the select_one question which appears in the first repeat instance and has no choice filter, and a second version of the select_one question which appears for all other instances 2...n.

For (2) something came up recently in another thread, but I don't know if I'll be able to locate it.

I've just created an entry in this compilation of ODK design patterns. Check the "repeat patterns" tab. And please read the cell comments. Here's a screenshot.

1 Like

Hi,
1- I think there's no direct way of doing it. The work around (2) suggested by Joseph should work, but when the choices are in the choice sheet.
2- You should be able to exit the repeat loop by using the GotoPrompt button, still you might get an error at the end when you validate. Sounds to me in your car the max number of repeat is not always fixed. Possible solutions could be to:
2.a) change the value dynamically based on the answers before launching the loop
2.b) instead of using a Max value, have a note/acknowledge message appearing notifying the user that some iterations are missing. The note/acknowledge would be relevant only if the number of loops you have done so far is less than the max desired. User could still choose to go ahead, but at least s/he was warned and has acknowledge this.