Choice filter with an if where else is no filter?

1. What is the problem? Be very detailed.
Hoping to have an if statement in the choice_filter where the else is to not apply any choice_filter at all

2. What app or server are you using and on what device and operating system? Include version numbers.
Latest ODK Collect

3. What you have you tried to fix the problem?

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

I have a question for an inspection type. In the following group I have a question for a category. If the inspection type = a, b, or c then the category should filter on the inspection type. However, if the inspection type is d or e, all categories should be available.

My choice_filter looks like this:
if(not(selected(${inspection_type}, 'd')),if(not(selected(${inspection_type},
'e')),inspection_type=${inspection_type}, inspection_type=''), inspection_type='')

And the choices look like this:
category category1 a
category category2 a
category category3
category category4 b
category category5 c
category category6 a
category category7
category category8
etc.
I'm hoping if inspection type is a, b, or the choices available are filtered as above. However if inspection type is d or e then all 8 categories are available. Unfortunately, the way my choice_filter is written currently only category3, category7, and category8 are available due to the else setting the filter to an empty string.

If you attach a section of the xlsform it will be easier to troubleshoot and give you a fully functioning example but the general idea should be something more like this...

inspection_type=${inspection_type} or selected(${inspection_type},'d') or selected(${inspection_type},'e')

Thankfully the choice_filter functionality has a significant amount of flexibility and should be able to do what you want without needing any if() statements.

1 Like

Ah, I see! I figured by specifying 'd' and 'e' in the choice filter it would not return any choices at all since they were not specified options on the choices tab. This works great, thank you!

For anyone else needing a visual example see attached.choice_filter_test.xlsx (10.5 KB) choice_filter_test.xml (4.2 KB)

1 Like