I’m building a survey in KoboToolbox with several repeat groups, and I need skip logic that depends on answers from an earlier, non-adjacent group (not just the immediately preceding question).
A few things I’m running into:
Is there a clean way to reference answers from outside the current repeat group in a relevant column expression, or do I need to restructure the form?
Does using indexed-repeat() or ${group_name} referencing get unreliable once you’re several groups deep?
Any best practices for keeping skip logic maintainable as the form grows, without it becoming a tangle of nested conditions?
Would appreciate any XLSForm patterns or examples from people who’ve solved this in a larger form.
The adjacency of the group doesn’t actually matter - questions referenced in skip-logic can be anywhere in the form; in fact, they can even be after (!).
If you need to reference questions within a repeat group from outside the repeat, then you need to use the indexed-repeat() function. Basically, because the question is repeated multiple times, you have to tell it with specific iteration of the repeat to lookup; that’s what the indexed-repeat() function does.
There’s no specific issues with multi-level indexed-repeat() or regular nested groups. However, Enketo/Kobo Web Forms does have some issues with nested repeats, especially once you get 3-levels deep (ie a repeat within a repeat within a repeat…). If you find you are writing multi-level nested repeats then you may want to consider refactoring your form.
So long are you keep your skip logic well, logical, then its pretty straight forward. Although as I said you can reference other questions anywhere in your form (even after), universally you almost always want to skip something as a consequence of something you answered earlier; ie the antecedent. So I might suggest having the antecedent question(s) either immediately before the stuff you want to skip, or else have a section at the beginning of your form where all this critical info is asked early on, which you then reference subsequently to determine what sections of your form to include/skip.
I’d also recommend making all these antecedent questions required (so that you are not having to deal with potential blank responses in your skip logic). And if a lot of things are dependent on the same thing, consider putting them all inside a group and putting the relevant condition/skip logic on the group as a whole, instead of on each individual question. That will make your form cleaner and easier to read.