Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple_form: Remove outer label for an inline checkbox with label

Using Simple_form 2.0.2

The simple form code using HAML:

= f.input :remember_me, as: :boolean, inline_label: 'Remember me'

But it renders this:

<div class="control-group boolean optional">
  <label class="boolean optional control-label" for="admin_remember_me">Remember me</label>
  <div class="controls">
    <input name="admin[remember_me]" type="hidden" value="0" />
    <label class="checkbox"><input class="boolean optional" id="admin_remember_me" name="admin[remember_me]" type="checkbox" value="1" />Remember me</label>
  </div>
</div>

How do I remove that first label that's rendered, so that I only have the inline label?

like image 603
David Nix Avatar asked Aug 24 '12 17:08

David Nix


3 Answers

You can use:

= f.input :remember_me, as: :boolean, inline_label: 'Remember me', label: false
like image 55
Hernan S. Avatar answered Oct 19 '22 19:10

Hernan S.


Found a solution after much Google fu.

Use input_field instead of input which won't automatically generate a label.

= f.input_field :remember_me, as: :boolean, inline_label: 'Remember me'
like image 27
David Nix Avatar answered Oct 19 '22 20:10

David Nix


For whom it doesn't work

= f.input_field ...

Use this way

= f.check_box ...

like image 11
Sergiy Seletskyy Avatar answered Oct 19 '22 18:10

Sergiy Seletskyy