Search code examples
ruby-on-railsformssimple-form

Adding * to required form labels


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.


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?