I have a need for a preference in my smart app which will allow multiple selection.
I can’t figure out from the documentation how I am supposed to act on this once it is set.
If I create
input(name: “modes”, multiple: true, type: “enum”, title: “Make Mode buttons”, options: [“Cool”,“Dry”,“Heat”]), required: true
How do I code a check to see if “Cool” was selected ?
Will modes be a string with comma’s, an array, a list of some type ?
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
2
What is the result if you log.debug “$settings”?
Or log.debug modes
Etc. For a start anyway. You should be able to tell if the result is a Groovy List (essentially an array, of course), since printas will show square brackets, right??
If not shown as a List, then it’s likely a string, but you can check this by running string methods against it (instead of Collection / List operations…).
It prints as follows
initialize: modes=[Dry, Cool],basename=Bedroom
unfortunately contains is a string method meaning the string contains substring.
So even with this code we don’t know if it is a string or a list
the debug output looks like a list
I have the code working with contains.
1 Like
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
6
This will return a boolean for whether or not the input “modes” contains “cool”
So in an if statement you could do this:
if(modes.contains("cool")){
//do something of modes contains cool
}
else if (!modes.contains("cool")){
//if modes does not contain cool
//do something
}