26

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.

Jonathan Allard
  • 18,429
  • 11
  • 54
  • 75
Chip
  • 1,653
  • 2
  • 20
  • 27

4 Answers4

43

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}" }
rafaelfranca
  • 3,285
  • 24
  • 15
20

You can also do

simple_form_for @model, :defaults => {:required => false}
AlexBrand
  • 11,971
  • 20
  • 87
  • 132
6

on Rails 4 just remove the "required" word

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

so it should be

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

Validation still works!

rafaecheve
  • 1,226
  • 1
  • 9
  • 4
0

just

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

and restart your rails server. Then it works.

alsotang
  • 1,520
  • 1
  • 13
  • 15
  • 1
    Having a validator on a attribute [overrides](https://github.com/plataformatec/simple_form/blob/v3.1.0/lib/simple_form/helpers/required.rb#L10-18) this setting. – x-yuri Mar 20 '15 at 16:54