Radio button required field class

21 views
Skip to first unread message

M,Gopi M.gopinath

unread,
Oct 17, 2014, 3:46:49 AM10/17/14
to rubyonra...@googlegroups.com
Hi,

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

<td colspan="2">
<label for="stay_connected_form_gender">I am <span class="astris">*</span></label>
<%= f.radio_button :gender, 'm', :class => 'RadioInput' %>Male
<%= f.radio_button :gender, 'f', :class => 'RadioInput' %>Female
</td>

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


Colin Law

unread,
Oct 17, 2014, 4:03:41 AM10/17/14
to rubyonra...@googlegroups.com
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

Matt Jones

unread,
Oct 17, 2014, 7:10:23 PM10/17/14
to rubyonra...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages