Formtastic单选按钮没有每个单选按钮的标签
问题描述:
我正在使用activeadmin。我需要为单选按钮设置一个无标签的单选按钮。像下面的图片Formtastic单选按钮没有每个单选按钮的标签
f.input :star_rating, as: :radio, collection: (1..5), label:false
删除字段标签,但它一直在标签为每个单选按钮
答
你可以尝试使用member_label选项
正如你可以调用一个Proc它你可以简单地设置PROC返回什么,或者如果你想的明星还有,返回一个明星...
https://github.com/justinfrench/formtastic/wiki/4.1-Options-Cheat-Sheet
答
我在一段时间后得到了解决方案。
在这里,我愿把对他人的解决方案:
<%= f.input :star_rating, as: :radio, collection: (1..5).collect { |c| ['', c, {:disabled => c <=2, title: "#{c} star"}] } %>
为了让明星的图像作为标签:(我用SASS)
#hotel_star_rating_input li.choice {
float: left;
width: 30px;
label {
height: 25px;
background: url('star.png') no-repeat 2px bottom;
}
}
答
您可以通过空字符串作为标签收集选项:
f.input :star_rating,
as: :radio,
label: false,
collection: [['', 1], ['', 2], ['', 3], ['', 4], ['', 5]]
,这会使得拉迪o没有标签的按钮。
哇!使用member_label实现该功能会很好,现在将试用 – Muntasim
Option **:member_label ** *已被弃用*。这个[pull request](https://github.com/justinfrench/formtastic/pull/1094)解释了你应该使用什么。 – yesnik