# How do I create a radio button group?

**URL:** https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151
**Category:** Scripts & Extensions
**Created:** [May 19, 2024, 12:16pm UTC](https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151 "2024-05-19T12:16:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sudo\_whoami](https://community.aseprite.org/user_avatar/community.aseprite.org/sudo_whoami/32/6531_2.png) [@sudo\_whoami](https://community.aseprite.org/u/sudo_whoami)
#### Post date: [May 19, 2024, 12:16pm UTC](https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151/1 "2024-05-19T12:16:32Z")

</div>

I’m trying to create a group of three radio buttons, the first of which is “selected” by default and the other two are false, but I can’t figure out how to group them together. Currently, the first of the three is active, but when I click on the others they just activate too (and stay that way) rather than behaving as a group.

I’ve tried:

- Giving each button the same `id`
- Adding a `group="radioGroup"` to each
- Passing the same `onclick` function to each

---

<div class="post-metadata">

### Author: ![sudo\_whoami](https://community.aseprite.org/user_avatar/community.aseprite.org/sudo_whoami/32/6531_2.png) [@sudo\_whoami](https://community.aseprite.org/u/sudo_whoami)
#### Post date: [May 19, 2024, 12:41pm UTC](https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151/2 "2024-05-19T12:41:12Z")

</div>

The strangeness continues…

This doesn’t work (using `label` to mark the `radio` buttons):

```auto
local dlg = Dialog("No Dice")
    :separator{ text="Apply to frames" }
    :radio{ id="applyAll", label="All", selected=true, onclick=selectFrameRange }

    :newrow()
    :radio{ id="applyRange", label="Range", onclick=selectFrameRange }
    :number{ id="firstFrame", text="1", decimals=0 }
    :label{ text="to" }
    :number{ id="lastFrame", text=tostring(numFrames), decimals=0 }

    :newrow()
    :radio{ id="applySelected", label="Selected", onclick=selectFrameRange }

    :separator()
    :button{ id="ok", text="OK" }
    :button{ id="cancel", text="Cancel" }
    :show()

```

but _this_ does (using `text` to mark them instead):

```auto
local dlg = Dialog("This works")
    :separator{ text="Apply to frames" }
    :radio{ id="applyAll", text="All", selected=true, onclick=selectFrameRange }

    :newrow()
    :radio{ id="applyRange", text="Range", onclick=selectFrameRange }
    :number{ id="firstFrame", text="1", decimals=0 }
    :label{ text="to" }
    :number{ id="lastFrame", text=tostring(numFrames), decimals=0 }

    :newrow()
    :radio{ id="applySelected", text="Selected", onclick=selectFrameRange }

    :separator()
    :button{ id="ok", text="OK" }
    :button{ id="cancel", text="Cancel" }
    :show()

```

Apparently using `label` at all breaks the radio group completely, even if they all have the same `label`. If anyone can explain this behavior I’d appreciate it. I feel like I’m almost certainly missing something.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [May 20, 2024, 10:04pm UTC](https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151/3 "2024-05-20T22:04:58Z")

</div>

Hi @sudo_whoami, the first `radio` that has a `label` creates a new group, use the `text` property to set the text of the specific `radio` option.

E.g.

```auto
local dlg = Dialog("Radio Groups")
 :radio{ label="Group1", text="A" }:newrow()
 :radio{ text="B" }:newrow()
 :radio{ text="C" }
 :radio{ label="Group2", text="A" }
 :radio{ text="B" }
 :radio{ text="C" }
 :separator()
 :button{ id="ok", text="OK" }
 :button{ id="cancel", text="Cancel" }
 :show()

```

![image](https://community.aseprite.org/uploads/default/original/3X/7/7/774a4aa1fb19270b80ac2feecf05c959109031c2.png)

---

<div class="post-metadata">

### Author: ![sudo\_whoami](https://community.aseprite.org/user_avatar/community.aseprite.org/sudo_whoami/32/6531_2.png) [@sudo\_whoami](https://community.aseprite.org/u/sudo_whoami)
#### Post date: [May 21, 2024, 2:02pm UTC](https://community.aseprite.org/t/how-do-i-create-a-radio-button-group/22151/4 "2024-05-21T14:02:19Z")

</div>

@dacap Ah, that makes sense. Thanks for the clarification!
