1

I have a vertical form using Simpleform, and in that form I have a checkbox collection as one of my inputs. The issue is the checkbox label is not inline with the box itself.

I found This on the simple form page: https://github.com/plataformatec/simple_form/wiki/Custom-Wrappers

However after putting that in the form, I get a Syntax Error:

/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

Here is the config wrapper code located in config/initializers/simple_form.rb just like on the wiki page:

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

And in my form I have:

<%= 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?" %>

I thought it could be because the wiki page is referring to a single checkbox and something would be different for a checkbox collection, but I'm not sure. Also, when I remove the :wrapper => :inline_checkbox, from the input above, I do not get a syntax error. Instead it simply displays the checkboxs with the label directly below the checkbox.

4

1 回答 1

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>
于 2013-10-22T20:58:27.480 回答