Forum: Ruby on Rails validate field with radio_button

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
fmh (Guest)
on 2008-10-15 01:42
(Received via mailing list)

i want validate my text_field only when the radio_button is clicked.
i try this but when i validate my form , the radio button lost focus
and validate is not checked

<%= radio_button("user","type",
"private",:onclick=>"Element.hide('compagny')") %>Private
<%= radio_button ("user","type",
"compagny",:onclick=>"'compagny')", :onchange=>
visual_effect(:Highlight, "compagny"))%>Compagny


validates_presence_of     :compagny_name , :if => :type_required?

def type_required?
   return true unless type = "compagny"
This topic is locked and can not be replied to.