Honor simple_form my blank / blank label

Using simple_form v2.1.0 in a Rails 3.2.13 application. I have simple_form where I want the flag to display with an inline label, and I want to have a "blank" normal label. Thus, the container with labels should remain in place, and the flag will be correctly positioned with other elements of the form.

If I install :label => ""or :label => " "or :label => nilor do not provide at all :label, I get the field name as a label.

If I set :label => false, the label and containing elements are not displayed at all (therefore, the checkbox is displayed in the far left corner of the page).

If I install :label => " ", I get the literal text  , as expected.

There seems to be no way to tell the simple form to leave a label there, just don't put the text in your container.

Here is an example form where I am trying to set an empty label for a checkbox with an embedded label.

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

But simple_form thinks it is smarter than me and uses a shortcut by default. I would like this to be done only if I have not specifically provided a shortcut!

Simple form doesn't allow blank labels!

+3
source share
3 answers

You tried to completely remove the attribute :labelon your input and use it form.labelfor an empty label instead .

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

Instead of using an empty label, you can put your flag in CSS.

0
source

:label false.

:. SimpleForm ActionView , : locale , ,

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

Had similar problems. In your default form, simply do the following:

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

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

.blanklabel { color: white; }

0
source

All Articles