Community Health Toolkit

Displaying dynamic screens

I have an input variable which contains a list of values. I would like to display each value on a separate screen.

Here’s how the input variable looks like:

calculate	mitigation_list										instance('contact-summary')/context/mitigation_list														

The size of the list keeps on changing based on what was captured in the previous form. Hence, the need for dynamic screens.

Each screen will display the value from the list. So, screen one will display value1, screen 2 will display value2, etc etc.

I know that in order to repeat a screen, I need to use begin repeat. However, how do I set the loop so that every value is displayed on a separate screen?

Also, how do I display the value ?

1 Like

If your repeat group has appearance of field-list and your style in the Settings tab is pages then you will get each one on a separate screen. You can then use calculate and notes accordingly to show the values. I think you’ll find this ODK recipe page helpful for figuring that piece out.

This seems like a scenario that could be helpful for others – would you be able to share it as a guide on the docs site once you’ve got it working?

We are currently unable to get the current index via position(…) when looping through a repeat. This will be possible once we upgrade to the latest enketo in a future release cc @gareth

In trying to follow the example provided in the link which you shared, I came across this function position(..). However this seems not to work on CHT v3.9.1 with an error The string 'position(\"\n \n \n \")' is not a valid XPath expression."].
I would like to be able to generate the questions from a predefined space delimited array. If I could get the position() to work or any other alternative will be great. select-at(${myArray},0) works okay, now I need to use variable instead of hardcoding 0.

That does seem trickier without being able to use position(). An alternative that could work right now is to hard code multiple pages and use relevant conditions to only show the ones needed. Although not elegant, the end result to the user may be the same.

In the long term we should make sure that position works as expected, which I noted in the cht-core issue for upgrading Enketo to latest. For posterity and follow-up it would be good to open a bug report for position specifically, and any other function that doesn’t behave as expected.