gpt4 book ai didi

html - 如何将开关切换按钮添加到 Rails 中的简单表单

转载 作者:太空狗 更新时间:2023-10-29 15:59:20 25 4
gpt4 key购买 nike

我正在使用 Rails 4 和 Simple Form with Bootstrap。

我希望我的复选框不会那样:

<%= c.input :my_bool_field, label: false, class: "form-control" %>

enter image description here

但是类似的东西(我有那个的 CSS)

<label class="switch switch-primary">
<input type="checkbox" />
<span></span>
</label>

enter image description here

我知道我可以使用 simple_form 包装器,但我发现它们有点令人困惑。有人可以帮我创建具有该样式的复选框吗?

最佳答案

您能否转到此链接并查看“开关”。 getbootstrap.com

enter image description here

我希望这个例子对你有用,我目前使用的是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com