1

How can I get simple form to not wrap check_box in label tag

<%= simple_nested_form_for @project,
                             url: project_path(@project),
                             html: {
                               id: "project-form",
                               class: "form",
                             } do |f| %>

    <%= f.association :tasks,
                  collection: Task.options_for_select,
                  as: :check_boxes,
                  required: false %>

    <%= f.input :hold %>


  <% end %>

current result

<label for="task_ids_8">
  <input class="check_boxes optional" type="checkbox" value="8" name="task_ids" id="task_ids_8">Structure</label>

desired result

<label for="task_ids_8">Structure</label>
<input class="check_boxes optional" type="checkbox" value="8" name="task_ids" id="task_ids_8">

I need to know how to do this for the individual "hold" input and the collection.

bonum_cete
  • 4,730
  • 6
  • 32
  • 56
  • Have you tried: `<%= f.check_box :hold %>` or `<%= f.input_field :hold %>` as [suggested here](http://stackoverflow.com/a/18913719/3366016) for newer rails. – user3366016 Nov 10 '16 at 18:14
  • I have. For the individual inputs I will have to add an html label. That's fine. I'm still not sure how to address the collection though. – bonum_cete Nov 10 '16 at 18:27
  • Setting the `boolean_style: :inline` according to the docs should do it.https://github.com/plataformatec/simple_form#stripping-away-all-wrapper-divs Other examples lean towards the same thing but with slightly different declarations. `<%= f.association :tasks, collection: Task.options_for_select, as: :check_boxes, required: false, boolean_style: :inline %>` – user3366016 Nov 10 '16 at 18:44
  • So that did get the check box out of the label, but the label is still clickable because it has the "for" attribute still :/ – bonum_cete Nov 14 '16 at 17:06
  • I just convinced product the labels should be clickable, because they should be clickable – bonum_cete Nov 18 '16 at 18:10
  • good call. It is typically behavior to have the label clickable anyway. Moving comments to answer. – user3366016 Nov 18 '16 at 18:26

1 Answers1

0

For the one-off checkbox you can use one of these:

<%= f.check_box :hold %> 

or

<%= f.input_field :hold %> 

as suggested here for newer rails.

For the collection you can set the boolean_style: :inline according to the docs. Other examples lean towards the same thing but with slightly different declarations.

Use this:

<%= f.association :tasks, collection: Task.options_for_select, as: :check_boxes, required: false, boolean_style: :inline %>

Community
  • 1
  • 1
user3366016
  • 1,267
  • 2
  • 18
  • 31