Cascading selects in a repeat group & indexed repeat

Cascading selects within repeats require using current() to specify the filter you want to apply. If you have a first variable named city and a second one named neighborhood, your filter for the neighborhood would contain something like current()/../city. Unfortunately, there's a bug in Collect that makes this fail. current()/city does work now but it will be changed in the next release (likely late October or early November). You can read more at Quick tech call: rectifying current() in choice filter.

If you absolutely need to use this now, you can use an expression like current()/city. Every time that question is answered, you will get a dialog warning you about the impending change. You will need to change your forms for them to work with the next version. More about the dialog at Collect: Use of current() in a choice filter.

EDIT: here's a bit more context, especially for @Grzesiek2010:
XLSForm allows us to access fields within a form with special ${} syntax. It expands this to an absolute path so something like /data/my_repeat/my_variable. If ${} is used to refer to a variable within a repeat, that's a problem because there's an ambiguity about which repetition's variable we want to access. When Collect runs into that kind of ambiguity, it throws up that message about using indexed-repeat().

In most cases, using indexed-repeat can solve the problem as it's just a wrapper to produce the XPath syntax that gets us to the value that belongs to a specific repeat (e.g. /data/my_repeat[7]/my_variable[1]).

When we use a choice filter, that's actually an XPath predicate. That means we end up with something like /data/my_repeat/neighborhood[city = ...]. In that predicate, . refers to the predicate itself. So to refer to a question that is a sibling of the question that has a choice filter, we need to use current(). current() refers to the node that has the predicate (e.g. /data/my_repeat/neighborhood).

We could use choice filter in this context, but we run into the same problem as I described above -- to get the position in the repeat, we'd have to do position(current()/..) and that is affected by the same bug.

2 Likes