Question

Does anybody have a nice way of adding * to required form labels, without having to turn to tools like SimpleForm?

I did not like the way SimpleForm added all these weird wrappers and classes to my stuff. I thought the point of SimpleForm was to allow you to write simple, semantic form ERB (which it most certainly does) - but not at the same time mess up your existing layout by adding wrappers and classes at random. I always style my forms before I bring them to Rails, so I like to tell it what classes to use, not the other way around.

Was it helpful?

Solution

Can't you just simply style your labels?

Your label:

<label class="required">MyRequiredField</label>

Your css.

label.required:after{content:"*"}

Or am I missing what you're trying to accomplish?

OTHER TIPS

If you don't like their solution you can see how they implemented and roll your own:

https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/helpers/required.rb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top