I have a partial that gets rendered in response to a #link_to_remote call. What I want to do is to display a select box, when the user selects an item from that box, display a second select box, when the user selects an item from that box, display a link (or possibly a submit button) allowing the user to do something.
Here is my partial:
<%= select_tag "use_part", options_for_select(@parts, @use_part), :onchange => "#{remote_function(:url => "select_assembly", :update => "disposition", :with => "'use_part='+$('use_part').value")}" %> <% if @use_part %> <%= select_tag "use_lot", options_for_select(@lots, @use_lot), :onchange => "#{remote_function(:url => "select_assembly", :update => "disposition", :with => "'use_lot='+$('use_lot').value+'&use_part='+$('use_part').value")}" %> <% end %>
<% if @use_lot %> <%= link_to_remote "Use", :url => {:action => "use_in_assembly"}, :update => "disposition", :with => "'use_lot='+$('use_lot').value+'&use_part='+$('use_part').value+'&id='+$('id').value" %> <% end %>
This works, but it seems pretty ugly, especially the bid where I keep appending more and more variables to the :with clause. As I was thinking about this last night, I started wondering if perhaps I should have used the #remote_form_tag helper. That way, when the form was submitted, the data contained in the form would be POSTed along with it and I wouldn't have to keep appending parameters to the :with clause.
The problem is (if it isn't obvious by now), I haven't the foggiest idea what I'm doing. Should I add an :onchange clause to the remote form tag? If so, what javascript function should it call? Should it include the :update => "disposition" option, indicating that the result should replace the contents of the "disposition" div (BTW, this partial is the only thing within that div). Should the select tags (continue to) have the :update option invoking the #select_assembly action on my controller?
I'll keep muddling through this and will probably learn some answers sooner or later (or possibly give up in a blue depressive funk), but I thought I would ask what other folks do or have done.
--wpd