Search code examples
ruby-on-railstwitter-bootstrap-3simple-form

How to add sr-only class to input's label?


I have simple form:

<%= simple_form_for @link do |f| %>
  <%= f.input :url, placeholder: "http://..." %>
  <%= f.button :submit, "Submit Link", class: "btn-primary" %>
<% end %>

it outputs input like this:

<div class="form-group url required link_url">
  <label class="url required control-label" for="link_url">
    <abbr title="required">*</abbr> Url
  </label>
  <input class="string url required form-control" placeholder="http://..." type="url" name="link[url]" id="link_url">
</div>

How can I add 'sr-only' class to label element?


Solution

  • Just do:

    <%= f.input :url, placeholder: "http://...", label_html: { class: 'sr-only' } %>