Remove outer label from collection_check_boxes

﹥>﹥吖頭↗ 提交于 2019-12-10 18:27:12

问题


I am generating a table from my association checkboxes. Each row shows a checkbox and some additional information.

%table
= f.collection_check_boxes :task_ids, @my_collection, :id, :label do |r|
  %tr
    %td= r.label
    %td= r.check_box
    %td= r.object.due_date

But this breaks my HTML since the output looks like this:

<table>
<span><label for="task_ids_1"> <--- I want to remove this...
  <tr>
    <td><label for="task_ids_1">My Name</label></td>
    <td><input type="checkbox" value="8" name="user[task_ids][]" id="task_ids_1" /></td>
    <td>I'm in.</td>
  </tr>
</label></span> <--- ...and this!
</table>

Of course I tried to set label: false, but this option has no effect. How can I get rid of the outer label?


回答1:


I finally figured it out by myself almost one year later. There is an option called boolean_style: :inline that makes it work.

%table
  = f.collection_check_boxes :task_ids, @coll, :id, :label, boolean_style: :inline do |r|
    %tr
      %td= r.label
      %td= r.check_box
      %td= r.object.due_date

I found the solution and explanation here https://github.com/plataformatec/simple_form/issues/1266:

Since you want it to be inline (because you're making it nested by yourself) you need to use boolean_style: :inline config.



来源:https://stackoverflow.com/questions/37975486/remove-outer-label-from-collection-check-boxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!