Skip to content

Two-way binding for grouped radio inputs #311

Closed
@Rich-Harris

Description

@Rich-Harris

Via #10 / #309. In Ractive, you could do this:

<label>
  <input type="radio" value="Alpha" name='{{selected}}' />Alpha
</label>

<label>
  <input type="radio" value="Beta" name='{{selected}}' />Beta
</label>

<label>
  <input type="radio" value="Gamma" name='{{selected}}' />Gamma
</label>

<p>selected: {{selected}}</p>

The name='{{selected}}' sort of makes sense, in that a shared name identifies the radios as belonging to the same group, but only sort of, since you're not actually binding to the name.

A possible alternative — keen to hear what people think:

<label>
  <input type="radio" value="Alpha" name='whatever' bind:group='selected' />Alpha
</label>

In other words, selected would take the value of whichever radio in the group of those with name='whatever' was checked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions