I have a Rails form that allows the user to choose from a collection of objects with checkboxes, and also to choose an optional one of those as the "Primary" choice. However, there is not always a primary choice, and as it stands now if the user accidentally clicks on a radio button, there doesn't seem to be a way for the casual user to de-select it.
<%= form_tag song_part_singer_parts_path(@song, @part) do %>
<input type="hidden" name="song_id" value="<%= @song.id %>" />
<table>
<tr>
<th>Singer</th>
<th>Primary?</th>
</tr>
<% Singer.active.each do |s| %>
<tr>
<td>
<%= check_box_tag "singer_ids[]", s.id %>
<%= s.name %>
</td>
<td>
<%= radio_button_tag "primary", s.id %>
</td>
</tr>
<% end %>
</table>
<%= submit_tag "Update" %>
<% end %>
Edit: Further research suggests that this is not possible, by design of the radio button. I would also accept other solutions to this problem. I need the user to have the ability to choose zero or one options, but not more, and to correct a mistake if they made it.