Rails: How to disable asterisk on form's required fields?

vsync picture vsync · Oct 4, 2011 · Viewed 33.4k times · Source

When I add the 'Required' attribute
to html input fields, Rails pre-pends an asterisk (*) before the label.

Does anyone know how to prevent this?

For some reason Rails transforms this:

<%= f.input :Company, :input_html => {:value => "", :id => "company_name"}, :label => "company name" %>

into this:

<div class="input string required">
    <label for="company_name" class="string required">
    <abbr title="required">*</abbr> company name</label>
    <input type="text" value="" size="50" required="required" name="lead[Company]" id="company_name" class="string required">
</div>

I don't like that it wraps everything in a DIV and adds an ABBR element to the party.

How can I prevent this?

Answer

RocketR picture RocketR · Oct 5, 2011

You can just set the required mark to empty value in simple_form's locale file:

en:
  simple_form:
    required:
      text: 'required'
      mark: '*'

Or use CSS to hide it.