Get to know the selected/unselected item from a switch group

Hi there,
I have had a lot of issues while trying to know which value I am selecting or unselecting on the switch group component.

Exemple :
Capture d’écran 2023-03-15 à 14.38.35
Here, if I unselect "option3" i want to know that the item "option3" has been unselected.

My use case is that I also have a search bar to get into the values of the switch group, but while selecting/unselecting an item having a filter, the switch group doesn't recognize the previous values.

Thank you for any help !

Hi @Gabriel_Ferrier

Great question! It seems like you can use Javascript & temporary state to determine the most recently clicked item.

1). Create a temporary state variable, set the initial value to be equal to the default value of the switchGroup

2). Create a JS query that will trigger on change of the switchGroup. The JS query will compare the state value with the current value of the switchGroup, get the difference (i.e. the clicked value), and then it will update the state to the new value of the switchGroup:

let difference = _.concat( _.difference(state1.value, switchGroup1.value),  _.difference(switchGroup1.value, state1.value))
state1.setValue(switchGroup1.value)
return difference

Please note, you may have to modify this code if you need to also determine whether the returned value is toggled on or off. This code will just tell you which item was most recently clicked