Using XLSForm for Survey123 Connect, how do I create a choice filter on a cascading multi-select?

3421
8
Jump to solution
03-29-2019 11:04 AM
AlexaTodd
New Contributor II

I need to change the type of the conditional question ("Target pest subcategory") so that more than one can be selected:

However, the filtering does not work when I change the type from select_one to select_multiple:

QA (TargetPestCategories) references 7 options from the 'choices' sheet (image below). 3 of these options have subcategories that are within another list referenced by QB (TargetPestSubCategory).

QB contains a relevant query...

selected(${TargetPestCategories},'Plant_Disease') or selected(${TargetPestCategories}, 'Indoor_Pest') or selected(${TargetPestCategories}, 'Habitat_Restoration')

...and a filter:

filter=${TargetPestCategories}

This is what the survey looks like when I remove the filter:

Any ideas how I can filter the conditional question while still allowing for multiple selections?

0 Kudos
1 Solution

Accepted Solutions
AlexaTodd
New Contributor II

Found a solution to this problem. Attached is the simplified form.

Summary:

Rather than using a filter for each category, I added a new choice list for each and added them as separate questions that appear when relevant. At this point, the requirement was not working to ensure at least one from the multiple choice list was selected. The solution was adding an additional hidden field that calculates the count of the selection using an if statement to determine which list is relevant, and if no list is relevant outputs 1. This was important for allowing categories without subcategories to be valid on their own. All of these questions are null field types, so that they are not recorded in the database. The subcategories are recorded in the database in a hidden question that uses a calculation to join any subcategory selections.

Details:

  • Create a new choice list for each target pest w/ subcategories
  • Add a question for each pest w/ subcategories with the following parameters:

type

select_multiple

required

yes

relevant

selected(${TargetPestCategories}, '[pest w/ subcategories]')

bind::esri:fieldType

null

  • Add a hidden question with the following parameters:

constraint

.>=1

required

yes

calculation

if(selected(${TargetPestCategories}, 'Habitat_Restoration'), count-selected(${SelectedHabitatRestoration}), if(selected(${TargetPestCategories}, 'Indoor_Pest'), count-selected(${SelectedIndoorPest}), if(selected(${TargetPestCategories}, 'Plant_Disease'), count-selected(${SelectedPlantDisease}),1)))

bind::esri:fieldType

null

  • Set up the TargetPestSubCategory field with the following parameters:

type

hidden

required

yes

relevant

selected(${TargetPestCategories}, 'Habitat_Restoration') or selected(${TargetPestCategories}, 'Indoor_Pest') or selected(${TargetPestCategories}, 'Plant_Disease')

calculation

join(',',${SelectedHabitatRestoration}, ${SelectedIndoorPest}, ${SelectedPlantDisease})

View solution in original post

0 Kudos
8 Replies
BrandonArmstrong
Esri Regular Contributor

Hi Alexa,

Unfortunately, cascading selects are not supported by multiple choice type questions. We do have an open enhancement request for adopting support in a future release, which I will add you too.

A few previous GeoNet posts that might offer some assistance can be found here...

https://community.esri.com/thread/229228-survey123-choicefilter-using-static-string-on-cascading-sel...

https://community.esri.com/thread/198277-using-choicefilter-with-a-selectmultiple-question

Best,

Brandon

0 Kudos
AlexaTodd
New Contributor II

Thought I found a work around, but now I'm dealing with another issue. To get multiple selections of the subcategory, I've added a repeat that is also conditionally relevant depending on the category that is selected in the first question. The problem is if the user changes the first question after submitting a repeat, the choice(s) that is/are already selected remain, and the final result is a mix of choices that do not all match the first category. 

Is there a way to ensure the selected repeats all match the appropriate filter for the final relevant category? Perhaps using jr:choice-name?

0 Kudos
AlexaTodd
New Contributor II

I've created a copy of my survey with the portion I'm having issues with. Please see the attached table where I have attempted to solve the problem with the addition of a repeat. Now the issue is adding logic that links the two questions so that if the category changes, the subcategory is reset. 

Is it possible to combine jr:choice-name with regex to get the name from the label and use this to define what is relevant?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Alexa,

You should see the choices change with a change to the dropdown.  That being said, the design you have in the form is a bit unstable; if a user were to switch to a non-plant primary category, it would make the repeat non-relevant, losing the data of all the repeats.  It might make more sense to have the primary category inside the repeat.

0 Kudos
AlexaTodd
New Contributor II

Still having issues with the solution. This section is inside a repeat. As far as my testing indicates, the calculated question with a constraint works only if it is not hidden. Is this true? Must a question be visible to trigger a validation error?

EDIT: When the question entry that is not valid (i.e., no subcategories are selected) is visible in the displayed repeat, the validation works. However, if the question entry that is being displayed is valid, then the validation is not triggered for the other (not visible) repeat entry.

0 Kudos
DougBrowning
MVP Esteemed Contributor

You may be hitting this known issue.  https://community.esri.com/thread/231800-survey-allowed-to-be-submitted-when-required-questions-are-... 

Workaround is to put a group around it.

AlexaTodd
New Contributor II

That works! Thank you. Creating a new group around the questions and moving the relevant formula to the "begin group" row made the requirement function correctly on the question within the group.

0 Kudos
AlexaTodd
New Contributor II

Found a solution to this problem. Attached is the simplified form.

Summary:

Rather than using a filter for each category, I added a new choice list for each and added them as separate questions that appear when relevant. At this point, the requirement was not working to ensure at least one from the multiple choice list was selected. The solution was adding an additional hidden field that calculates the count of the selection using an if statement to determine which list is relevant, and if no list is relevant outputs 1. This was important for allowing categories without subcategories to be valid on their own. All of these questions are null field types, so that they are not recorded in the database. The subcategories are recorded in the database in a hidden question that uses a calculation to join any subcategory selections.

Details:

  • Create a new choice list for each target pest w/ subcategories
  • Add a question for each pest w/ subcategories with the following parameters:

type

select_multiple

required

yes

relevant

selected(${TargetPestCategories}, '[pest w/ subcategories]')

bind::esri:fieldType

null

  • Add a hidden question with the following parameters:

constraint

.>=1

required

yes

calculation

if(selected(${TargetPestCategories}, 'Habitat_Restoration'), count-selected(${SelectedHabitatRestoration}), if(selected(${TargetPestCategories}, 'Indoor_Pest'), count-selected(${SelectedIndoorPest}), if(selected(${TargetPestCategories}, 'Plant_Disease'), count-selected(${SelectedPlantDisease}),1)))

bind::esri:fieldType

null

  • Set up the TargetPestSubCategory field with the following parameters:

type

hidden

required

yes

relevant

selected(${TargetPestCategories}, 'Habitat_Restoration') or selected(${TargetPestCategories}, 'Indoor_Pest') or selected(${TargetPestCategories}, 'Plant_Disease')

calculation

join(',',${SelectedHabitatRestoration}, ${SelectedIndoorPest}, ${SelectedPlantDisease})

0 Kudos