Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Simple_Form Gem -remove required (*) prepend [duplicate]

I'm tearing my hair out trying to figure out how to use Simple Form. I want to remove that "*" prepended to required fields. I still want validations, but I don't want that styling.

I have tried each of the suggestions in this post: Rails simple_form attribute required mark (*)

I have also tried all of the suggestions in the post marked as a duplicate in the comment below. None of these work. Simple Form is not simple.

I'm using rails with simple form and bootstrap.

I have currently got this in my initialiser.rb

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

I have removed "mark: "*" from the simple_form.yml file. I have restarted the server. These incredibly frustrating * are still showing.

How do you get rid of the * on required fields?

like image 815
Mel Avatar asked Nov 13 '15 06:11

Mel


1 Answers

Go to config/initializers/simple_form.rb

Find this line (around line 100)

How the label text should be generated altogether with the required text.

Then uncommented the below line.

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

Remove #{required} completely so you have

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

Alternatively you can go to config/locales/simple_form.en.yml

Find mark: '*' (around line 7) and remove the Asterisk so you have mark: ''

Restart your server after either instance.

Hope this helps.

like image 153
vanburen Avatar answered Oct 16 '22 05:10

vanburen