Multiple choice option in Field Maps

9742
28
10-06-2021 08:30 AM
Status: Open
Labels (1)
ZoeBroek
Occasional Contributor

I'd like to have a multiple choice option in Fieldmaps. The current version of Field Maps (Oct 2021) has  limited options for data collection. When collecting an attribute value I sometimes need people to fill in multiple values form the same domain list. I'd like them to be able to select multiple values from the combobox or radio buttons. 

I'm hoping this function will be added with the new function of creating elements form scratch (kinda like the different options in de survey123, preferably the Multiple Choice) but also not like that, because I need them to use my domain values and not create a new field.

Does anyone have a smart workaround for this in the meantime? 

28 Comments
JessicaShue

Hi @Woodpecker,

  I was able to implement your code to create an options list and field to show the multiple choices selected by the field crew, but I'm running into a glitch in Field Maps. When a mistake is made and the field crew selects 'clear list', the app freezes and twitches. They have to cancel editing that feature and start all over again. We are working offline, but when testing it happens when online as well. The iOS is up to date as is the Field Maps app.

Has anyone else seen this?

  I am using your solution on 3 separate fields, and it happens when selecting clear list on any of them. They have 13, 9, and 19 choices - one of which is label:  'clear list'/code: 'CL'. Here is my Arcade code used for one of these fields:

var selection = $feature["code_choices"]
var thisFieldValue = $feature["codes_currentCensus"]

if (IsEmpty(thisFieldValue)) {
    return selection
   
} else if (selection == "CL") {
    return ''
   
} else if (Find(selection, thisFieldValue) != -1) {
    return thisFieldValue

} else {
    return thisFieldValue + ',' + selection
}
Woodpecker

@JessicaShue we are mostly using Android devices and it seems to work ok, though I've noticed this issue sometimes in the browser. This was happening maybe 6 months ago, but now it seems to run ok. 

I haven't tried it, but it might help to add a space in the second return statement. The second return statement returns an empty field, so the script might somehow be stuck in an infinite loop between first and second return? 

So have a go by simply adding a space between the single quotes like this so the script doesn't return an empty field: 

else if (selection == "CL") {
    return ' '
 
Hope this solves it. 
 
Cheers
JessicaShue

Thanks @Woodpecker! I was able to get it working using the suggestion from @JustinReynolds. The next app I set up I'll test this out again.

AyeletGreenberg

@JessicaShue , 
I also encountered a similar problem where I could not update or submit new points after clearing the list.  I tried the solution that @Woodpecker  suggested, and it works, but then after clearing the list the comma stayed at the beginning of the list, and it looked like this:   , yellow, blue, red...

I tried a different approach and added it to the original code. See below.
After cleaning the list, the Options field shows the ‘Clear List’ value, and the Options_List field shows the ‘empty’ value, but if you tap the X in the Options field, it clears them both, and you can then submit a cleared field. See the attached screenshots.

var selection = $feature["Options"];
var thisFieldValue = $feature["Options_List"];

if (selection == "Clear List") {
    return 'empty';
} else if (IsEmpty(thisFieldValue)) {
    return selection;
} else if (thisFieldValue == "empty") {
    return selection;
} else if (thisFieldValue == "Clear List") {
    return '';
} else if (Find(selection, thisFieldValue) != -1) {
    return thisFieldValue;
} else {
    return thisFieldValue + ', ' + selection;
}

 

Clear List.png

 I hope it helps.
@Woodpecker - thanks a lot for sharing the original code!

PiaN
by

Thank you @JustinReynolds and @Woodpecker, both of your options work great in the Field Maps app, however, I can not get them configured to work in the Edit on a browser, e.g. Instant App or Web Map. Any thoughts or ideas?

It only accepts one option and just replaces a previous selection, different to what it does when using the field maps app.

JamesPoeschel

I would also like to see this as an option.

Survey123 is great but it does not work with multiple different feature layers.

dzahsh
by

Here is perhaps a more straight forward version of this two-field solution. 

var a=$feature.OPTIONS_FIELD;
var b=$feature.VALUES_FIELD;
var c=', ' //delimiter

if(a=='Clear'){return};
b=Split(b,c,-1,true); //Split existing values into array
if(!IsEmpty(a)&&!Includes(b,a)){Push(b,a)} //Add new value to array if needed
return Concatenate(b,c) //Concatenate and return new values

 @JustinReynolds I find that the editableExpression code for toggling editability works in the Field Maps app but in Map Viewer in a browser the values get jumbled. Have you seen this?

Jeremy_Z

@PiaN , I'm trying to use these codes and running into the same issue in the browser, but haven't tried in Field Maps as of yet.

@JustinReynolds and @Woodpecker, have you run into this at all?

@dzahsh I'm trying your code as it's so clean, but having this issue there as well. Someone looking at the code with me said the Return line should have it return ' ' to clear the list, though I've not gotten that to work either, at least in browsers.