Category: Question and Answers
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Change container’s shadow color based on a switch position

Issue

I am looking for a way to change the container shadow color and label based on a switch. If the switch is on, I want the shadow color to be green and the label to say "On". If the switch is off, I want the shadow color to be red and the label to be invisible. I am wondering how to achieve this with JS.

Resolution

To change the container shadow color and label text based on the position of a switch, you can use App Theming in the upcoming release. This will allow you to use JavaScript to control the container’s shadow color. However, if you only need to change the label text, you can set the label property to {{Switch1.isSwitchedOn ? "On" : ""}}. This code example assumes that Switch1 is the name of your Switch widget and will display the text "On" if the switch is on and display nothing if the switch is off.