Filtering select_one options based on select_multiple

Dear team;

I am wondering if there is a way to filter select_one option list based on a previous select_multiple?
If anyone has may you kindly share.
Thank you!!

Hi @cmuchuchuti!

Generally you can filter choices based on a choice_filter:
https://docs.odk-x.org/xlsx-converter-using/?highlight=choice_filter#id11
Some modification may need to be made in terms of thinking through the selects in a select_multiple but the idea will be the same.

Thanks @elmps2018. Would really appreciate if anyone has ever done this filtering. I have tried all options I could think of but seems not to be working out.

1 Like

@cmuchuchuti can you provide us with an example of what you have tried so we can take a look and offer suggestions.

1 Like

HI @W_Brunette some of the options I tried seem a bit far and I seemed to be just far from the solution. For example I tried:

  • choice_filter===data(‘multiple_selection variable’)

Another option I also tried was to have a constraint to check if the select_one choice entered is amongst the select_multiple choices selected. I tried using the js includes but again it didn’t work.

1 Like

@cmuchuchuti

The problem is that choice_filter is an object and the value for a select_multiple is an array. You could use _.contains (See https://underscorejs.org/#contains) to check if an array contains an item.

For example,

_.contains(data('select_multiple_variable'), choice_filter.data_value)

You can find an example at app-designer/app/config/tables/Ethiopia_household/forms/Ethiopia_household at master · odk-x/app-designer · GitHub

Another option is to use the selected function.

selected(data('select_multiple_variable'), choice_filter.data_value)
2 Likes