Radio button required field class

Hi,

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

On 17 October 2014 08:46, M,Gopi M.gopinath [email protected]
wrote:

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.

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.

Colin

On Friday, 17 October 2014 03:46:49 UTC-4, M,Gopi M.gopinath wrote:

<%= f.radio_button :gender, ‘f’, :class => ‘RadioInput’ %>Female
I need to get a single validation msg if none of the radio button is
selected.

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:

http://www.w3.org/TR/html401/interact/forms.html#radio

–Matt J.