我正在使用 Rails 4 和 Simple Form with Bootstrap。
我希望我的复选框不会那样:
<%= c.input :my_bool_field, label: false, class: "form-control" %>
但类似的东西(我有CSS)
<label class="switch switch-primary">
<input type="checkbox" />
<span></span>
</label>
我知道我可以使用 simple_form 包装器,但我发现它们有点令人困惑。有人可以帮我创建具有该样式的复选框吗?
您可以访问此链接并查看“开关”吗?getbootstrap.com https://getbootstrap.com/docs/4.3/components/forms/#switches
我希望这个例子对你有用,我目前使用 Bootstrap 4.3 和 Rails 5.2;
使用模型形式的“自定义开关”及其工作原理:
-- 模型/_form.html.erb
<%= form_with(model: employee, local: true) do |form| %>
<div class="custom-control custom-switch">
<%= form.check_box :active, class: "custom-control-input", id: "customSwitch1" %>
<label class="custom-control-label" for="customSwitch1">Status: </label>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
我希望对你有帮助,我是 Rails 和 Bootstrap 的新手。
Regards!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)