Can you calculate a hidden field removing the underscore from a select_multiple

2267
5
Jump to solution
06-29-2017 11:29 AM
MichaelStranovsky
Occasional Contributor

I am using a select_multiple which list First_Lastname as the choices.   Is there a way to calculate a hidden field with the result of the selection, but remove the underscores from the results?

1 Solution

Accepted Solutions
CarolineRose
New Contributor III

I have found a very roundabout way to remove the underscores from a select_multiple response. I would love to hear if there is a different way to accomplish this, but here is how I did it:

1) For each option in the 'select_multiple' question, add a hidden question below. Use the calculate column to test whether an option was selected, then to populate that hidden question with either the corrected text (with spaces) or null if that option was not selected.

      1.5) If you don't mind some extra commas in your list, you can simply add another text question and use the       calculate column to "join" all of the hidden questions. Your result is a list of corrected text, but with some extra       commas in the list if you didn't choose a name in the middle of the list.

2) Let's assume that you want no extra commas in the list. Then we need a few more steps. First, go back and add the separator characters (comma-space) to each of the corrected text strings.

3) Then join those using an empty string as the separator:

4) Because you don't know which option will be the last selected, your list will now include a trailing comma-space. We can use substring to remove the trailing comma-space if you want.

(BONUS) 5) But what if we want to include an option to add other names, not in the pre-defined list? First, add 'other' as an option in your select_multiple list on the choices tab.

6) Then add a text question for the user to fill in other names. Use the 'relevant' column to make it visible only when 'Other' has been selected. Add it to the list of questions in the join.

Now we have another problem: the 'other' entry might not include a trailing separator, and therefore might delete the last two characters that we typed:

7) To get around this problem, we could test whether the final two characters are 'comma-space' and only remove them if they are 'comma-space':

Of course, people can enter anything they want into the 'other' text box, and it will delete a trailing comma-space even if they intended for it to stay...

😎 Now you can use 'bind Esri field type' set to null to prevent the layer from saving all of your hidden questions.

Conclusion: it's possible to hack your way to a list of values with spaces, but it takes a lot of setup!

View solution in original post

5 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Michael,

If the underscores are always at a known position in the string (like in sixth_character the underscore is character # 6), then you could use the substr() function to extract parts of the text and reassemble them- in the case above (assuming it in a question called 'q'):

substr(${q},0,5) + substr(${q},6,string-length(${q}))

would give us "sixthcharacter"

That being said, is it possible to change the values of the select so they don't have underscores?

0 Kudos
MichaelStranovsky
Occasional Contributor

No the underscore will vary in location and also will reside in multiple locations.   The select multiple choices are First and Last names. 

0 Kudos
CarolineRose
New Contributor III

I have found a very roundabout way to remove the underscores from a select_multiple response. I would love to hear if there is a different way to accomplish this, but here is how I did it:

1) For each option in the 'select_multiple' question, add a hidden question below. Use the calculate column to test whether an option was selected, then to populate that hidden question with either the corrected text (with spaces) or null if that option was not selected.

      1.5) If you don't mind some extra commas in your list, you can simply add another text question and use the       calculate column to "join" all of the hidden questions. Your result is a list of corrected text, but with some extra       commas in the list if you didn't choose a name in the middle of the list.

2) Let's assume that you want no extra commas in the list. Then we need a few more steps. First, go back and add the separator characters (comma-space) to each of the corrected text strings.

3) Then join those using an empty string as the separator:

4) Because you don't know which option will be the last selected, your list will now include a trailing comma-space. We can use substring to remove the trailing comma-space if you want.

(BONUS) 5) But what if we want to include an option to add other names, not in the pre-defined list? First, add 'other' as an option in your select_multiple list on the choices tab.

6) Then add a text question for the user to fill in other names. Use the 'relevant' column to make it visible only when 'Other' has been selected. Add it to the list of questions in the join.

Now we have another problem: the 'other' entry might not include a trailing separator, and therefore might delete the last two characters that we typed:

7) To get around this problem, we could test whether the final two characters are 'comma-space' and only remove them if they are 'comma-space':

Of course, people can enter anything they want into the 'other' text box, and it will delete a trailing comma-space even if they intended for it to stay...

😎 Now you can use 'bind Esri field type' set to null to prevent the layer from saving all of your hidden questions.

Conclusion: it's possible to hack your way to a list of values with spaces, but it takes a lot of setup!

MichaelStranovsky
Occasional Contributor

Hi Caroline,

Great work...this was a big help.   Thank you again.  

0 Kudos
Danielle_Papineau
Occasional Contributor II

Hi Caroline Rose,

Great post!  Thanks so much for sharing.  Have you seen or used the jr:choice-name() calculation?  It is great when you need to retrieve the label of a list choice, similar to what you are doing in the first step.  More on that here:  Survey123 Tricks of the Trade: XLSForm function... | GeoNet 

 

Since you've looked pretty far into this select_multiple question, I was wondering if you've had issues with using and displaying the results of this question type specifically in Operation Dashboard.  Since the result of this question gives a comma delimited list, it's pretty much not usable in that app.  There have been several other posts about it, but I haven't seen an solutions or even any suggestions.  Was curious to know if you use Ops Dashboard and maybe found a workaround for this?

Thanks!