Displaying space delimited string in a repeat group

I have a space delimited string of 3 dates and I want to display each date on a single screen inside a repeat group. I am have create a calculate field with the following calculation but not sure how to get the running index of the repeat group so that I can display each date on it’s screen.

selected-at(${last_3_reported_dates},index)

1 Like

Currently, I don’t know of a reliable way to achieve this. However, with an upcoming* Enketo uplift, you should be able to do it using the same function as above:

type name label calculation
text in space delimited text
begin_repeat repeat Output
calculate val selected-at(${in},position(..) - 1)
note out ${val}
end_repeat

You can try the Enketo uplift branch locally by upgrading to this pre-release:

* Please note that this is not yet supported and should not be used in production. It is planned to be released with CHT 4.0, but there is no guarantee that it will.

5 Likes

+1 to what @binod said! Just want to add that the CHWordle form has some examples of using the position function inside a repeat (but as Binod mentioned, this needs the new Enketo version coming with CHT 4.0).

Also, for that it is worth, I am comfortable guaranteeing that the Enketo uplift will be released with CHT 4.0 :smile:. Development on that branch is complete and testing for it is 99% done. It will be merged soon!

4 Likes

My situation is very similar - using a repeat group to loop through a select_multiple list, count-selected number of repeats.
I have encountered some abnormal behaviour:

  • position(..) can’t be evaluated
  • position() works, but the counter does not update (always 1) - so selected-at(${list}, position() - 1) returns info of the first item for each iteration. everything else seems to be working fine.

Screenshot 2022-09-02 at 06.58.32





Note: cht -v: 3.15.0

As was mentioned above, the position function does not really work in current versions of the CHT (requires 4.0). In the past, I have spent considerable time trying to find a workaround that would allow for functionality like what you are trying to achieve here with the repeat. Unfortunately, as far as I can tell, there is no way to make it work in current versions of the CHT. The necessary functions just do not integrate properly with the repeat in that version of Enketo.

The only viable approach that I know of here is the brute-force method of basically having separate dedicated qty and balance fields for each drug (and toggling their relevance based on what is selected in drugs).

1 Like