how to remove asterisk in required fields when using simple form?

泪湿孤枕 提交于 2021-02-10 16:47:47

问题


In the simple_form initializer there is this line

  # How the label text should be generated altogether with the required text.
  # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }

I removed the comment and changed it to

  # How the label text should be generated altogether with the required text.
   config.label_text = lambda { |label, required, explicit_label| "#{label}" }

But this doesnt affect the asterisk in the required fields. The * is still present in the labels. How can i remove the asterisk in the required field?

UPDATE:

I am uploading the image. The askterisk is present even after server restart.


回答1:


ok so i forgot when generating simple form i used bootstrap flag. That created a second initializer file called simple_form_bootstrap.rb. So the change had to be made in this file. After the change in this file, it is working.




回答2:


I believe a hacky fix is to just do it through css:

abbr[title="required"] {
  display: none;
}

replace abbrwith whatever selector selects the *



来源:https://stackoverflow.com/questions/52799060/how-to-remove-asterisk-in-required-fields-when-using-simple-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!