Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails simple_form attribute required mark (*)

I am using Simple Form in my app and I'd like to remove the * to indicate an attribute is required on all of my forms (existing and those yet to be created).

I have tried to set in simple_form.rb:

  # Whether attributes are required by default (or not). Default is true.   config.required_by_default = false 

And I've tried to modify simple_form.en.yml:

   required:       text: 'required'       mark: ''  # <------ tried setting this to blank. 

I know I can set :required => false on each field, but I want to clean up the views & set it once.

like image 672
Chip Avatar asked Sep 29 '11 04:09

Chip


2 Answers

Setting the simple_form.required.mask to '' should work if you restarted the server.

But you can remove it changing the the configuration:

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

to

config.label_text = proc { |label, required| "#{label}" } 
like image 70
rafaelfranca Avatar answered Oct 09 '22 22:10

rafaelfranca


You can also do

simple_form_for @model, :defaults => {:required => false} 
like image 25
AlexBrand Avatar answered Oct 09 '22 22:10

AlexBrand