Forum: Ruby on Rails validate field with radio_button

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffbe650dbc3cc97f561569ae0aa2994f?d=identicon&s=25 fmh (Guest)
on 2008-10-14 23:42
(Received via mailing list)
hello,

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

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

---model----

validates_presence_of     :compagny_name , :if => :type_required?

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