Hi. I have a form with two select lists, named ''project'' and ''activity''. The content of the ''activity'' list is changed when the selected item in project changes, using ''observe_field'' where project is observed, and a div enclosing ''activity'' is updated. This works as expected. The problem is that when submitting the form containing the two select list after they have changed, the value of the selected ''activity'' item is not included in the submitted values. If no change in the selects has occurred since the page was originally loaded, the value for ''activity'' is included, because the activity list is not generated by the ''observe_field'' the first time. So I guess the reason that the value of the ''activity'' select is missing is because it is generated by a Ajax call after the form is originally loaded, but how can I have the value of the selected ''activity'' to be included in the submitted values? Any ideas? André -- Posted via http://www.ruby-forum.com/.
Simon Santoro
2005-Nov-19 14:31 UTC
Re: Form values not included in submit when ajax generated.
André wrote:> Hi. > > I have a form with two select lists, named ''project'' and ''activity''.Can you send us some code? How do you use the observe_field helper, and what does the code you send back to the call looks like?
André M Bonkowski
2005-Nov-19 22:01 UTC
Re: Form values not included in submit when ajax generated.
Simon.Santoro wrote:> Can you send us some code? How do you use the observe_field helper, and > what does the code you send back to the call looks like?I am traversing an array of objects, lets call them items. For each item I creates a table row, and puts in the projects and activities selection lists there. As you can see I also creates a div with a different name for each of activity selection list for each row. ... ... <%= start_form_tag :action => ''save_item'' %> <% idx = 0 for @item in @items -%> <tr> <td><%= select("item[]" , "project_id", @projects.collect {|p| [ p.name, p.id ] }, {}, {:id => ''item_project_id_'' + idx.to_s}) -%></td> <td> <div id=''activities_<%= idx.to_s-%>''> <%= select("item[]", "activity_id", @projects[0].activities.collect {|pa| [ pa.name, pa.id ] }) %> </div> </td>></td></tr> <%= observe_field ''item_project_id_'' + idx.to_s, :frequency => 0.2, :update => ''activities_'' + idx.to_s, :url => { :action=> :activity_for_project }, :with => "''project_id='' + escape(value) + ''&''+ ''index=#{idx}'' + ''&''+ ''item_id=#{@item.id}''" -%> <% idx += 1 end %> ... ... The partial contains: <div id=''activities_<%= index.to_s-%>''> <%= select("item[]", "activity_id", @project_activities.collect {|pa| [ pa.name, pa.id ] }) %> </div> and the activity_for_project method in the controller: def activity_for_project @item = Item.find(params[:item_id]) if not @item @item = Item.new end @project_activities = Activity.find(:all, :conditions => "project_id = #{params[:project_id]}") render(:partial =>"activity_for_project", :object => @project_activities, :locals => {:index => params[:index]}) end André -- Posted via http://www.ruby-forum.com/.
André M Bonkowski
2005-Nov-22 21:34 UTC
Re: Form values not included in submit when ajax generated.
Hi again. After going through the rhtml once again I saw what caused my problem. It is as simple as that the start_form_tag started inside the table, with the corresponding end_form_tag after the </table> tag. Moving the start_form_tag before the <table> solved the problem. Feeling shameful? You bet! André -- Posted via http://www.ruby-forum.com/.