6

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?

Community
  • 1
  • 1
Mel
  • 2,481
  • 26
  • 113
  • 273
  • No - the suggestions are the same as the post I tagged. These aren't wroking – Mel Nov 13 '15 at 06:57
  • Except that as you said in your comment below, when you **actually** followed the advice (not commenting out the line, just making the value `""`) then it did actually work. – smathy Nov 13 '15 at 17:27
  • no - actually - that just makes the field blank - it doesnt switch it off – Mel Nov 13 '15 at 22:03

1 Answers1

8

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.

Community
  • 1
  • 1
vanburen
  • 21,502
  • 7
  • 28
  • 41
  • Hello, your suggestion for the initialiser is what I currently have. I changed the yml file to delete the mark. I restarted the server. They are still there – Mel Nov 13 '15 at 07:00
  • Actually, I commented out the entire line. Those * go away when you keep the line but make the mark blank – Mel Nov 13 '15 at 07:05
  • The first option does nothing - just in case others are facing the same teeth grindingly annoying problem – Mel Nov 13 '15 at 07:05
  • I've tested both ways and they both work but it may be dependent on the versions your running or another configuration. Glad you got it working though. – vanburen Nov 13 '15 at 07:07
  • It doesn't work with simple_form-3.2.0 – Mel Nov 13 '15 at 07:10
  • @Mel the answer [here](https://stackoverflow.com/questions/52799060/how-to-remove-asterisk-in-required-fields-when-using-simple-form) indicates you may have t adjust a simple_form_bootstrap initializer as well – ryan2johnson9 Apr 13 '20 at 22:35