4
votes

Using simple_form v2.1.0 in a Rails 3.2.13 app. I have a simple_form where I want to have a checkbox show up with an inline label, and I want to have an "empty" normal label. This way, the label's container should remain in place and the checkbox will be properly positioned with the other form elements.

If I set :label => "" or :label => " " or :label => nil or don't provide a :label at all, I end up with the field name as the label.

If I set :label => false, the label and containing elements aren't rendered at all (so the checkbox appears at the far left of the page).

If I set :label => " ", I end up with the literal text  , as expected.

It seems there is no way to tell simple form to leave the label there, just don't put any text in its container.

Here is an example form where I'm trying to setup an empty label for a checkbox with an inline label.

<%= simple_form_for @model ... %>
    <%= f.input :sticky, :label => "", :inline_label => "Sticky?", :as => :boolean ... %>
<% end %>

But simple_form thinks it's smarter than me and defaults the label. I wish it only did that if I hadn't specifically supplied a label!

Simple form doesn't allow blank labels!

3

3 Answers

0
votes

Have you tried removing the :label attribute in your input completely and instead using form.label for the empty label.

http://apidock.com/rails/ActionView/Helpers/FormHelper/label

Instead of using an empty label you could position your check box with CSS.

0
votes

Try setting :label value to false.

UPDATE: Since SimpleForm is supposed to rely on ActionView to render the elements, you can use this hackish solution: set the label in your locale file to empty string, like this

en:
  activerecord:
    attributes:
      model_name_underscored:
        sticky: ' '
0
votes

Was having similar troubles. In your form defaults just do this:

defaults: { :label => 'blanklabel', label_html: { class: 'blanklabel'}

Then in your CSS, just set the label text color to white:

.blanklabel { color: white; }