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

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


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.


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

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


I'm using Rails 3.1, and I have the following view code in my _form.html.erb for a given model:

<div>  <%= f.label :full_name %><br/>  <%= f.text_field :full_name, :required => true %><br/></div>

The label does not show an asterisk if you do it this way. Unless you post code I can't be sure of what your approach is and if my solution would fit said approach.

Updated Answer:It sounds like you've inherited this code from someone. At any rate, after reading your code sample, you are most definitely using the simple_form gem. Information about that gem can be found here https://github.com/plataformatec/simple_form. To answer your question though, if you change your code the following:

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

That should turn off the asterisk.

I would add, based on your disgust for the HTML generated from simple_form, it sounds like you should just do away with the gem and re-write your form code using the Rails default form helpers, which can be read about here http://guides.rubyonrails.org/form_helpers.html. Depending on the size of the code base, you might be better off just sucking it up and learning how to use the simple_form gem for the sake of saving time, but if you think you have the time to change it all, go for it.