【问题标题】:formtastic radio collection add a name to the groupformtastic 电台集合添加名称到组
【发布时间】:2015-06-30 13:40:28
【问题描述】:

如何为表单单选按钮集合中的一组单选按钮添加名称。我需要添加一个名称属性,以便在单击单选按钮时正确选中和取消选中单选按钮。我在

上尝试了几种变体
 <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>

上面的表单可以工作,但是没有 name 属性被添加到单选按钮组中。

输出以

开头
<div class="radio_buttons input optional form-group" id="product_selected_image_url_input">

【问题讨论】:

    标签: ruby-on-rails-4 formtastic radio-group


    【解决方案1】:

    我不知道为什么,但是通过将选中的属性设置为选中并在未选中的选项上取消设置此属性来单击单选按钮时,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>
    

    【讨论】:

      猜你喜欢
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 2015-10-01
      • 2015-09-10
      • 1970-01-01
      相关资源
      最近更新 更多