Validate field with radio_button

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