Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/7650689/rails-how-to-disable-asterisk-on-forms-required-fields

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In config/initializers/simple_form.rb add this line:

config.label_text = lambda { |label, required| "#{label}" }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...