Choice filters for multiple_select

Dear all

I am trying to filter answer choices for a multiple_select questions based on the answers from a previous multiple_select question (in our example, we are first asking about diagnosis of a participant and then based on this different choices for possible drugs the participant is taking should be displayed).

I used a category column in the choices sheet and a statement selected(${previous_var}, category) in the choice_filter column of the survey sheet. It works in the ODK online converter, but gives the following error message on CHT: message: “Could not evaluate: /model/instance[@id="other_drugs"]/root/item[selected( /model/instance[1]/cbl_main_bp_screening_test/oth_med_pr/t_other_dx , ‘category’)], message: Document.evaluate: The expression is not a legal expression”

name: “FormLogicError”

Does anyone have an idea how to solve this? Is there another way to use the choice filter function on CHT than I tried it?

Thank you very much!

Welcome to the CHT community @felixgerber!

It would be nice to know which CHT version you are using.
If you are using the latest version (4.x), then the selected() function in choice-filter should work:

However, if you are using 3.x version, then you can use another approach using contains:

contains(${previous_var}, category)

Here is the description of the function contains in the ODK docs:
Form Operators and Functions - ODK Docs (getodk.org)

Please make sure that the choice names are unique enough to not collide with each other.

It is recommended to use CHT 4.x because it has many improvements and bug fixes related to the ODK forms with upgraded Enketo.

2 Likes

Hi @felixgerber .I used contains(${pevious_choices}, choicesCategory} for version 3.x.x and it worked for me. I think 3.x.x uses an older version of enketo while 4.x.x uses a later version.

2 Likes

Dear @binod & @KiharaSimon

Thank you very much for your replies! We are using the latest CHT version, but we did not manage to make the selected() function in the choice-filter column work. However, the contains() function is doing the job!

Thanks again and all the best

1 Like