How do I find out the value of a switch in a switch group, if it's selected or not?

How do I find out the value of a switch in a switch group, if it's selected or not?

The somewhat helpful tooltip when typing in the object, shows the following options.

tooltip helper for properties for my object in retool

Looking at the documentation, shows more properties which can be used for the object.

My question is....
How do I find out the value of a switch in a switch group, if it's selected or not?

I do not consider starchart 9am as allowing me to decipher whether that switch is selected or not.

If it's been selected then starchart 9am will be in the .value array property
It's exactly like a multiselect box, the switchgroup value is the value of the selected items from your supplied list of options
What your screenshot shows is you're looking at the .values property which is all possible values not the selected one(s) which is .value

I've made some progress but it doesn't fully work.
If I leave all four options selected, the .value always shows the visible label by it

  • starchart 9am
  • starchart 2pm
  • starchat 7pm
  • starchart midnight

It doesn't show me which switch values have been selected and which ones haven't.

Is there an update on this?
Also I forgot to include an image in the 3rd post.

It looks like a bug. I checked it myself and can confirm the checkboxGroup.value does not change when pressing switches on Mobile. On the other hand, on Web app the similar behaviour works correctly.

@retool-team This looks like a bug. Is there any update on fixing this?

Hmm doesn't repro on my end with this app, can anyone share a video of the bug?
switch group jan 16 2024.json (4.6 KB)

1 Like

Following onward from the Support Hours, try these additional steps.

  1. It works within a "transformer" but not within a "resource query" that uses "retool database"
  2. Try adding [0] at the end then leaving all the switch fields blank

:wave: Thanks for joining! As discussed in office hours, the switch group's .value property only has a list of the values that are toggled on in the switch group, and it doesn't track the index of these values. The checkbox group operates in the same way

This is the current expected behavior, but if you wanted to return a list of all switch group items with true or false values (true = checked on), you could use Javascript. This will work in a transformer or query:

@preshetin We still haven't been able to find a bug here :disappointed: If you're able to share a recording, that would be helpful

After fixing linting errors I can confirm it works properly now. So no bug.

Thanks @Tess

Got it, thanks! :raised_hands:

How do I get this code to work? I've never used transformers before.

let y = 0;
while(y < 5){
  return {{starchartblocks.values.map(x=>{
    return{[x]:(starchartblocks.value?.find(y>y===x))? true : false } 
}) }}
y++;
}
  return {{starchartblocks.values.map(x=>{
    return{[x]:(starchartblocks.value?.find(y>y===x))? true : false } 
}) }}

I get this error.

ReferenceError: y is not defined

Hi @desbest

The finds (find(y>y===x)), look like they need a = added after the first y

You may also need to wrap starchartblocks.value in square brackets if it's not an array

It works now. Thank you for your help!