Rails:simple_form单选按钮切换(zurb基础)

zer*_*r02 5 html ruby-on-rails form-helpers simple-form zurb-foundation

我试图在Rails单选按钮上使用Zurb基金会的开关元件.

我有这个代码:

<%= simple_form_for @mymodel .... |f| %>

<%= f.input :active, as: :radio_buttons %>

<% end %>
Run Code Online (Sandbox Code Playgroud)

这会生成单选按钮.

我现在正在尝试实施zurb基础开关,因为它看起来更好.

Zurb基金会开关元件

默认开关的示例代码:

<div class="switch">
  <input id="x" name="switch-x" type="radio" checked>
  <label for="x" onclick="">Off</label>

  <input id="x1" name="switch-x" type="radio">
  <label for="x1" onclick="">On</label>

  <span></span>
</div>
Run Code Online (Sandbox Code Playgroud)

问题是,它看起来像这样:

<div class="switch">
    <div class="input radio_buttons optional mymodel_active">
    <label class="radio_buttons optional">active</label>
    <span class="radio">
    <input class="radio_buttons optional" id="mymodel_active_true" name="mymodel[active]" type="radio" value="true">
    <label class="collection_radio_buttons" for="mymodel_active_true">Yes</label>   
    </span>
    <span class="radio">
    <input checked="checked" class="radio_buttons optional" id="mymodel_active_false" name="mymodel[active]" type="radio" value="false">
    <label class="collection_radio_buttons" for="mymodel_active_false">No</label>
    </span>
    </div>
    <span></span>
</div>
Run Code Online (Sandbox Code Playgroud)

然后我添加:, label: false ,:input_html => { :onclick => ' ' }作为属性,调整到示例.它仍然不会在第一次之后切换?我现在有onclick=""输入,但我需要它在标签上.

 <%= f.label :active , input_html: { :onclick => ' ' } %>
Run Code Online (Sandbox Code Playgroud)

不管用.

有谁知道这个问题?谢谢

ste*_*nis 2

我建议您使用简单表单自定义包装器https://github.com/plataformatec/simple_form/wiki/Custom-Wrappers