This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Akash Soti
Posted Nov 21 - Read on Facebook

Guys, has anyone made radio buttons using states? I am stuck at a point where my radio buttons change state but I am not able to get my head around how to disable others when one is active.

4 Comments

Gregory J. Orton

I'm about to publish a module for customisable radio list. Give me until next week. :)

Andrew R McHugh

If you don't have a week, you can create an array with all of the radio button layers. Then when you want to activate one and deactivate the others, loop through the array, deactivate all of them, then after the array just activate the one you want.

Akash Soti

Thank you guys! I figured it out, Andrew R McHugh I was thinking on those lines but was unable to articulate it into code.

bg = new BackgroundLayer

container = new Layer
width: screen.width

radioButtons = []
for rb in [0..2]
rb = new Layer
width: 60
height: 60
image: "images/radio_off.png"
y: 58
x: 40+(rb*400)
name: "rb#{rb}"
parent: container
rb.states =
stateOn:
image: "images/radio_on.png"
radioButtons.push(rb)

#function that handles state change for the clicked radio button
radioStateChanger = (clickedRadioButton) ->
if clickedRadioButton.states.current.name == "stateOn"
clickedRadioButton.stateSwitch("default")
else
clickedRadioButton.stateSwitch("stateOn")

for rbutton in radioButtons
rbutton.on Events.Click, ->
collect = container.children
for c in collect
c.stateSwitch("default")
clicked = this
radioStateChanger(clicked)

Jacky Lee
Read the entire post on Facebook