Kim
Kim

Reputation: 2156

pass form_for object to partial in rjs

I have a form with a field location. Based on the location value selected, a partial is displayed.

<% form_for @expression, :url => { :controller => "expressions", :action => "update" } do |f| %>

Location: <%= f.select(:lcn_location, [['loc_A', 'loc_A'],
    ['loc_B', 'loc_B'],
    ['loc_B', 'loc_B']
  ]) %>

<!--observe location field-->
<%= observe_field(form_tag_id(f.object_name,:lcn_location),
  :url => {:controller => 'expressions',
    :action => :display_field},
  :with => "'location_value='+value+'&form_object=#{f}'"   //here i am passing the form object
) %>

<% end %>

**display_field.rjs

if (params[:location_value] == 'loc_A')
   page.replace(div_id,  :partial => "adjacent_to_location", :locals => {:f => params[:form_object]} );
else
 page.replace_html div_id, 'Hello World!'
end

**_adjacent_to_location.html.erb

<%= f.text_field  :lcn_adjacent_to , { :size => 55} %>

My question is how do I pass the form object to the partial using rjs? The above is not working.

Thanks a lot for your help.

Upvotes: 0

Views: 210

Answers (1)

Salil
Salil

Reputation: 47472

change

<%= f.text_field  :lcn_adjacent_to , { :size => 55} %>

to

<%= text_field_tag :expression, :lcn_adjacent_to , { :size => 55} %>

Upvotes: 1

Related Questions