我有一个使用Simpleform的垂直表单,在那个表单中我有一个复选框集合作为我的输入之一。问题是复选框标签不与框本身内联。
我在简单的表单页面上找到了这个:https://github.com/plataformatec/simple_form/wiki/Custom-Wrappers
然而,在将其放入表单后,我收到语法错误:
/Users/michaelgodek/Sites/Travvl/app/views/pins/_form.html.erb:16: syntax error, unexpected ',', expecting tASSOC
..."], ["Teenage (13-17 Years)"]], :last, :first, label: "What ...
... ^
Trace of template inclusion: app/views/pins/_form.html.erb, app/views/pins/new.html.erb
这是位于config/initializers/simple_form.rb
的配置包装代码,就像在wiki页面上一样:
config.wrappers :inline_checkbox, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
bb.use :input
bb.use :label_text
end
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end
在我的表格中,我有:
<%= f.collection_check_boxes :kids_age, :wrapper => :inline_checkbox, [["Infant (0-1 Year)"], ["Toddler (1-3 Years)"], ["Preschool (3-5 Years)"], ["School Age (6-10 Years)"], ["Preteen (11-12 Years)"], ["Teenage (13-17 Years)"]], :last, :first, label: "What age groups are the kids in?" %>
我认为可能是因为wiki页面指的是一个复选框,而且复选框集合会有所不同,但我不确定。此外,当我从上面的输入中删除:wrapper => :inline_checkbox,
时,我没有收到语法错误。相反,它只是在复选框的正下方显示带有标签的复选框。
答案 0 :(得分:1)
我离开它一段时间后想出来,然后回到它。我把它放在其他可能遇到它的人身上。
我确信有更多的方法可以做到这一点,但我在引导程序中遇到了label class="checkbox inline"
,只是将表单输入包装在其中并且它有效!就那么简单!现在我的表单输入如下所示:
<label class="checkbox inline">
<%= f.collection_check_boxes :kids_age, [["Infant (0-1 Year)"], ["Toddler (1-3 Years)"], ["Preschool (3-5 Years)"], ["School Age (6-10 Years)"], ["Preteen (11-12 Years)"], ["Teenage (13-17 Years)"]], :last, :first, label: "What age groups are the kids in?" %>
</label>