Radio button required field class


I need to add a required class in gender radio button. How this can be done.

I am * <%= f.radio_button :gender, 'm', :class => 'RadioInput' %>Male <%= f.radio_button :gender, 'f', :class => 'RadioInput' %>Female

classname = required

If I am adding like this then it display two validation message for each radio button.

<%= f.radio_button :gender, ‘m’, :class => ‘RadioInput required’ %>Male <%= f.radio_button :gender, ‘f’, :class => ‘RadioInput required’ %>Female

I need to get a single validation msg if none of the radio button is selected.

Thanks in advance …

Best Regards,

Gopinath M

Asssuming that the second one is for css purposes (or similar) then it would be better to move the class out to a surrounding element, the td, tr or even form for example.


What Colin said - there’s not a single “element” for radio buttons. You didn’t state which Javascript library you’re using, but presumably it has a solution for radio buttons.

Also note that the ability to not have any of them checked is widely supported among browsers but not in keeping with the standard:

–Matt Jones