Erwin
2009-Oct-11 23:25 UTC
updating a form.select based whenever another form.select change [ajax]
I have the following form :
<% form_for :registration, @registration, :url => { :action =>
"create" } , :html => {:class =>
''generalform''} do |form| %>
<%= render :partial => "form", :object => form %>
<%= form.submit "Register", :class => ''go''
%> <%= link_to
''Cancel'', registrations_path %>
<% end %>
with this partial : (2 form select)
<div class="set" id="site_fields"
style="margin-bottom:10px;">
<div class="setbox">
<%= form.label :trainee %><br />
<%= form.select(:trainee_id, @trainees.map {|s| [s.name, s.id]},
{:include_blank => ''- select a trainee -'' }, :style =>
"width:
200px;", :onchange => remote_function( :method => "post",
:with => "''trainee_id='' + value", :url =>
choose_registrations_path ) )%>
</div>
<div id="select_epath" class="setbox"
style="margin-left:10px;">
<%= form.label :educational_path %><br />
<%= form.select(:epath_id, @epaths.map {|g| [g.kp_path_name, g.id]},
{:include_blank => ''- select an educational path -'' },
:style =>
"width:200px;" ) %>
</div>
<div class="clear"></div>
</div>
whenever the first select change (trainee) an Ajax request is fired
(remote_function) and the choose action in controller registrations is
executed ... working well , based on the trainee _id , an array
@epaths should be displayed in the second form.select..
I I put the second select in a partial, I loose the form
should I write ALL the form in a select a refresh it, or can I refresh
only the 2 select ?
thanks for your help
erwin