Reputation: 10224
I have a form and a group of checkboxes. But I want the user to be able to only check ONE value, never more than one.
This is what I have and it works for more than one value; it's on a has many through association. But now the clients wants to check only ONE, not more than one. I don't want to make changes to the DB or the associations because this client might change her mind later.
<%= f.collection_check_boxes(:community_partner_organization_ids, CommunityPartnerOrganization.order('name'), :id, :name, {}, {:class => 'checkbox'}) {|input| input.label(:class => 'checkbox') { input.check_box + input.text }} %>
Upvotes: 0
Views: 2102
Reputation: 726
Radio buttons, by nature, only permit the selecting of a single element, and ActionView provides a helper just like collection_check_boxes!
Give something like this a try:
<%= f.collection_radio_buttons(:community_partner_organization_ids, CommunityParnerOrganization.order('name'), :id, :name) %>
Upvotes: 2