Hide/Show Text Field based on Selected value - ROR
Posted
by
Tau
on Stack Overflow
See other posts from Stack Overflow
or by Tau
Published on 2011-01-11T06:49:39Z
Indexed on
2011/01/11
6:53 UTC
Read the original article
Hit count: 247
ruby-on-rails
I am new to ROR. I am trying to show a "Others" text field only if the selected value is "others". I am trying to make hide/show function to be as general as possible, since I will need it in many controller. If anyone can help enlightening me, I will really appreciate it. BTW, I am using Rails 2.1.1 ruby 1.8.7
general_info.html.erb
<div>
<%= f.label :location_id, "Location:" %>
<%= f.collection_select(:location_id, Event.locations, :id, :name, {:prompt => true},
{:onchange => remote_function(
:url => {:action => "showHideDOMOther"},
:with => "'selectedText='+this.options[this.selectedIndex].text + '&other_div='+'loc_other'")}) %>
</div>
<div id="loc_other" style="display:none">
<%= f.label :location_others, "Others:" %>
<%= f.text_field :location_others %>
</div>
info_controller.rb
def showHideDomOther
render :update do |page|
page.showHideDOM("Others", params[:selectedText], params[:other_div])
end
end ...
application_helper.rb
def showHideDOM(targetString, selectedText, targetDiv)
if selectedText.casecmp targetString
page.hide targetDiv
else
page.show targetDiv
end
end
Seem to get the correct parameters value, but nothing seems to happen. This is what I see from the console when I changed the value of selection to "Others".
Parameters: {"action"=>"showHideDOMOther", "authenticity_token"=>"e7da7ce4631480b482e29da9c0fde4c026a7a70d", "other_div"=>"loc_other", "controller"=>"events", "selectedText"=>"Others"}
NoMethodError (undefined method search_generic_view_paths?' for #<EventsController:0xa41c720>):
/vendor/plugins/active_scaffold/lib/extensions/generic_view_paths.rb:40:in
find_template_extension_from_handler'
C:/usr/lib/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_finder.rb:138:in pick_template_extension'
C:/usr/lib/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_finder.rb:115:in
file_exists?'
:
Rendering C:/usr/lib/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/templates/rescues/layout.erb (internal_server_error)
© Stack Overflow or respective owner