Community Health Toolkit

Displaying multiselect question options based on relevancy condition


I have a multiselect question where each option should be displayed or hidden based on a relevancy condition. For example, in the below question, every single choice should have a relevancy condition. So, how can a choice filter help in this scenario?

Hi Iesmail,

Yes, it is possible to filter the options using choice_filter. Please have a look at this ODK doc which explains the feature with an example.


Hi @binod, please check my updated question. I am assuming a choice filter helps in a situation where you have cascading questions. But, in this case, every single option has a different relevancy condition.

May I know, what are the relevancy conditions? Are they based on the age of the woman or questions asked before in an another form? It is still possible to filter them based on these conditions, however, it might not be as straightforward as the example I have linked above.

They are inputs from the previous form.

In that case, we can make use of the context information as described in the Care Guides.

We can define some fields in the contact-summary-templated.js which can be accessed in an XForm field’s calculation.

Here is a relevant example from the CHT default config:

  1. In the contact-summary-templated.js, we collect all the known risk factors:
 ctx.risk_factor_codes = riskFactorCodes.join(' ');
  1. In the app form pregnancy_home_visit, we copy the risk factor codes into a field with name risk_factors_ctx, with this in the calculation:
  1. This is used to filter the risk factors shown in the form, with this choice-filter:
not(contains(${risk_factors_ctx}, name)) or name = 'none'

In this way, only the risk factors not already reported will show up in the options.

You may find it easier to follow the XLSX version of the form.