Rails simple_form - 是否可以只显示按钮标签的radio_buttons?

问题描述 投票:0回答:1

这段代码:

<%= f.input :exploratory, as: :radio_buttons,
  collection: [['Exploratory', true], ['Preparatory', false]],
  label: false %>

产生这个结果:

enter image description here

这几乎就是我想要的 - 唯一的问题是单选按钮上方的“探索”标签。

有没有办法让simple_form省略单选按钮组的标签,只显示各个按钮标签?或者,如果这是不可能的,有没有办法可以将标签设置为不同的值。

我正在使用带有Rails 5.2.3和Bootstrap 4.3.1的Simple Form 4.1.0。

ruby-on-rails simple-form
1个回答
1
投票

尝试添加label: false

<%= f.input :exploratory, as: :radio_buttons,
    collection: [['Exploratory', true], ['Preparatory', false]],
    label: false %>

这应该生成没有标签的HTML

经测试

enter image description here

此外,您可以通过添加label: 'Changed label'来更改标签

<%= f.input :exploratory, as: :radio_buttons,
    collection: [['Exploratory', true], ['Preparatory', false]],
    label: 'Changed Label' %>

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.