Could you provide more details and an example, please?
How you would like to show the follow-up reference? And how the listing? Are the follow-up questions different per no-choice? How will you need to evaluate/join the data in analysis?
It might be easier to directly put the related follow-up question after each leading question (and filter with a relevant).
Hint: As far as I know you cannot reference/get a question label.
This is to inform the farmer who has to realize the corrective measures at the end of the long survey (there are many more questions than in this example) about the the actions he has to take and to get his consent with a signature.
I am afraid, you will probaly need to duplicate (in some way) all question texts plus delai that need to be show.
For ex. with if expressions and concatenate. You might e.g. add a calculate variable for each question to store the text incl. delai to show (or empty). And at the end, concatenate/show all these text elements.
It seems you are using Collect, not Enketo. Right?
In the meantime I am following another approach, listing first all questions in a repeat group that retrieves the questions from a .csv. This has the advantage, that the coding in the xlsform gets much less crowded and questions can get managed independently from the form design. So far so good.
After the repeat, I want to list the data entered in "ra_mesures_correctives" in another repeat_group. This field only appears if "non" was first selected as a response to the initial question.
What does not properly work is the indexed-repeat. I do not manage to display the answers at the correct place.
When position(..) is "position(..)" no values are returned at all. If "position(..)-1" values are returned but at the wrong place.
Position(..) and indexed-repeat() start with 1. You might test the "position" references first with a fixed number, e.g. 1 or 2, to see what happens in your indexed-repeat note. (Even without the 2nd loop, directly after the end of your first repeat group.).
Hint: Please, test with the used design approach if data export is fine for further analysis. For ex. dynamic label parts will not be filled (column or choice names).
Also test that all references work correctly if you move back and delete/add/change a (referenced) loop element. You might need to pack all questions inside the repeat in an additional group, with a relevant control.
This approach is indeed much easier and neat in terms of coding.
The issue with position() and the indexed-repeat() was the -1, as @wroos mentioned, position() based indices starts at 1 and only if they have to match a select_multiple or other arrays they would need the -1 to mimic the start to 0.
The solution in the file you shared was almost complete. the only tweak would be recapping the entire repeat() and use relevant on a group to display or hide summary based on {oui, non, ra}. I modified the form to reflect these changes. I also added more info from previous repeat to allow enumerator to see what measures are linked to which question/observations (feel free to remove or add as needed).
The are few more considerations depending on how you indent to use the data in the second repeat:
the use on note type does not return any data in the exports. text or calculate would yield some data in the exports
the repeat_count() of both repeats need to be identical. In your form the count is coming from the csv. this won't be an efficient way to get dynamic counts, I would suggest you set those manually or dynamically using i.e.: a select_multiple() or csv with interview type and max number of questions.
The use of coalesce() in your form isn't necessary (since the question has no relevant and is required | in other words this questions won't be skipped) but if this is needed in the future, i would suggest maintaining same data-type as in your case coalesce(${ra_select},0)='oui' empty answers will become 0 which is not part of the name for your select options.
Hoping this helps (I tested the form and it worked for me).
Hint: Better adapt the coalesce parameter typing to the specification, https://getodk.github.io/xforms-spec/#fn:coalesce. If the final result should be a number, use number( coalesce(${stringVar}, 'stringValue' ). Better don't trust too much on automatic internal type castings, which might also be different between Collect and Enketo.
I tested the adapted from @jules_rugwiro. It did not work at all on Enketo but with ODK Collect all seems fine. I never tested my original version in Collect, although this is how the data will be collected. Stupid enough ! But our team should be able to verify and approve the submissions in the office using Enketo. How to resolve this?
Could you please explain the function of the two groups within the repeats? OK. Its to restrict the repeats to the restrain. Correct?
I also do not properly understand the function of this formula "indexed-repeat(${ra_cal_non},${ra_repeat},position(${ra_repeat_rec})) = 1" as a restriction on the group in the second repeat. OK. I think I understand it now. Means a restriction on wether the answer in the frist repeat group is "non". Correct?
Many thanks for your help and happy weekend to you!
Daniel
There is a number of benefits from using identical repeat counts (1) data exports can easily be matched, (2) less coding and headache to retrieve varying position() and (3) auto-updates when forms are edited. I added another section to demo how you could achieve selective repeat using join()
Could you please explain the function of the two groups within the repeats? OK. Its to restrict the repeats to the restrain. Correct?
Correct, these groups were added to (1) bypass the need to set relevant for all enclosed questions and (2) to minimise screen movement by showing each iteration on one window
I also do not properly understand the function of this formula "indexed-repeat(${ra_cal_non},${ra_repeat},position(${ra_repeat_rec})) = 1" as a restriction on the group in the second repeat. OK. I think I understand it now. Means a restriction on wether the answer in the frist repeat group is "non". Correct?
Correct, this is the relevant to allow enumerator to see questions where non was used.
I still think the .csv based pulling of questions is more elegant and flexible, though, the same results could be achieved using select_multiple (see both examples in the attachment. You will need to swap the survey sheets to test either). As for webforms unfortunately, the form behaves differently on Enketo, hence, recommending Collect for data collection and using alternative solutions for data validation/approval.
Sorry, it depends on your analysis process. It might even be disadvantage to blow up the join with empty cases. Image a household survey with questions on HH level and repeats for HH members. Normally, for analysis you would use one dataset for questions on household level (case) and a joined dataset for its members or a special selection of them (but no empties), adding some HH basics per join.
Hint: Please, test with the used design approach if data export is fine for further analysis. For ex. dynamic label parts will not be filled (column or choice names).
Also test that all references work correctly if you move back and delete/add/change a (referenced) loop element (or value, e.g. "no").
I have tested and adapted the different approaches and came up with this version: test_ra.xlsx (13.3 KB)
It works both on Enketo and Collect. If the form would not have worked on Enketo I would have gone back to the original heavy coded version where all questions are in the form. Just to stick to the known workflow for data validation the team is used to.
I have tested the form and have not found any problems so far. Although the forms behaves tricky on wether there are nested groups within the repeat_groups or not. In Collect the form also stops after one iteration of the first repeat if repeat_count is retrieved with pulldata from the .csv, but works fine in Enketo. We can live with a fixed number. But ideas on how to automise this are still welcome.
Let me know if you have any concerns about the actual form design.