How do you add a name to a group of radio buttons in a formtastic radio button collection. I need to add a name attribute in order that the radio buttons are checked and unchecked properly when one is clicked. I've tried a couple of variations on
<div class="product-image-form" >
<%= semantic_form_for [:admin, product], remote: true do |f| %>
<div class="product-images">
<h4>Select image</h4>
<%= f.input :selected_image_url, as: :radio, collection: product.product_images.map { |image| [image_tag(product_image.image_url).thumb, {class: selected_image_class(product,image)}), image.image_url,
{'data-huge-image' => image.big_product_image} ]}, input_html: {name: {"product[selected_image_url"}} %>
<%= f.actions %>
</div>
<% end %>
</div>
The above form works but no name attribute is added to the radio button group.
The output starts with
<div class="radio_buttons input optional form-group" id="product_selected_image_url_input">
答案 0 :(得分:0)
我不确定原因,但是通过将checked属性设置为选中并在未选中的选项上取消设置此属性,单击单选按钮时,formtastic表单未正确注册。我的解决方案是替换formtastic并使用rails helper radio_collection_button。
<div class="product-image-form" >
<%= form_for [:admin, product], remote: true do |f| %>
<div class="product-images">
<h4>Select image</h4>
<%= f.collection_radio_buttons :selected_image_url, product.product_images, :image_url, :id do |b|
b.label(:"data-huge-image" => "#{b.object.big_product_image}", class: selected_image_class(product,b.object)) { b.radio_button + image_tag("#{b.object.image_url}").thumb) }
end %>
</div>
<% end %>
</div>