Multiple Choice Contstraint

663
5
01-27-2023 04:22 AM
SeanWalsh
New Contributor

I have a multiple choice question with three options, the third being neither.  I want the survey to de-select the other(s) if neither is chosen or vice versa.  I found the below code when using google but nothing happens when i use that.  

 

not(selected(., 'option_c') and selected(., 'not_option_c'))

 

0 Kudos
5 Replies
Richard_Purkis
Esri Contributor

Hi @SeanWalsh 

I was able to make it work with the following syntax:

  • not(selected(${exampleChoice}, 'not_option_c') and count-selected(${exampleChoice}) > 1)

It doesn't deselect as such but it will return invalid if the constraint fails

Hope this helps

0 Kudos
SeanWalsh
New Contributor

That didn't do anything.  Maybe I'm plugging in the wrong information? Also this goes in the constraint column correct?

not(selected(${form_d_foultime}, 'Neither') and count-selected(${form_d_foultime}) > 1)
0 Kudos
Richard_Purkis
Esri Contributor

@SeanWalsh 

It should work in both the field app and web browser. May you share your xlsx form either in a reply or via direct message.

Thanks

0 Kudos
Richard_Purkis
Esri Contributor

@SeanWalsh You need to match the capitalization of your neither in the choice list, since the response would be 'neither', your statement looking for 'Neither' would never evaluate to False. 

not(selected(${form_d_foultime}, 'neither') and count-selected(${form_d_foultime}) > 1)

Thanks

0 Kudos
IsmaelChivite
Esri Notable Contributor

Automatically selecting/unselecting choices in a select_multiple, based on the user's selection, it not possible. This would involve a calculation in the select_multiple that uses select_multiple selection as an input. The XLSForm validator will flag this as a dependency cycle.

Logically, an expression like this would achieve what @SeanWalsh requested.

IsmaelChivite_0-1674827311902.png

Unfortunately, this will return an XLSForm validation error.

As @Richard_Purkis suggested, one could put together an expression to validate the user input. That is, to make sure that if Neither is selected, no other options are.

This is one example:

IsmaelChivite_1-1674828042216.png

Note that the expression is not in the calculation column. Instead, it is a constraint.

All in all, the post was a bit confusing because the title Multiple Choice Contstraint hinted that @SeanWalsh wanted to build a constraint, but then the description clarified that what was needed was a recalculation. In any event: You can get a constraint, but not recalculate the values.