作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 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
我希望这个例子对你有用,我目前使用的是 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 的新手。
问候!
关于html - 如何将开关切换按钮添加到 Rails 中的简单表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39594248/
我是一名优秀的程序员,十分优秀!