Cayce Balara
2006-Sep-17 16:04 UTC
AJAX/RJS issue: observe_form not passing in form params
I''m having a problem with an AJAX form. I currently have a working version as follows: In my _picker.rhtml partial I have: <%= observe_form "picker_form", :update => "frame_picker" , :loading_text => "Retrieving price...", :complete => visual_effect(:highlight, "picker_live_price", { :startcolor => "''#9b3801''", :endcolor => "''#f0c18e''", :duration => 0.5 }), :url => { :controller => ''store'', :action => "update_picker" } %> In my store_controller.rb controller I have: def update_picker @frame = Frame.find(:first, :conditions => ["category = :category", params[:frame]]) @quantity = params[:picker_quantity] render :partial => ''/store/picker'' end If I inspect the params array in the controller, it looks like: {"action" => "update_picker", "frame" => {...}, "controller" => "store"} This is all good and it works. However, for some usability reasons, I want to change this to use RJS. So, I''ve done the following: In the partial, I removed the :update and :complete pieces of the observe_form call that will now be handled by the rjs template: <%= observe_form "picker_form" :loading_text => "Retrieving price...", :url => { :controller => ''store'', :action => "update_picker" } %> In the controller, I removed the render call: def update_picker @frame = Frame.find(:first, :conditions => ["category = :category", params[:frame]]) @quantity = params[:picker_quantity] end I added the update_picker.rjs rjs template: page[:frame_picker].replace_html :partial => ''picker'' page[:picker_live_price].visual_effect :highlight, :startcolor => "''#9b3801''", :endcolor => "''#f0c18e''" This does not work - I get an error on the Frame.find line in the controller''s ''update_picker'' action, because params[:frame] is nil. If I inspect the params array, it looks like: {"action" => "update_picker", "controller" => "store"}. Notice that the frame key and values are no longer there. So, the problem appears to be that the form values are not getting passed through from the observe_form command to the controller in this second version. What have I done to account for the observe_form command changing what it is passing through to the controller?>>> NOTE: The first field in my form is a radio button - does that make any kind of difference?I would appreciate any help. thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Cayce Balara
2006-Sep-17 16:12 UTC
Re: AJAX/RJS issue: observe_form not passing in form params
Through some further research, I''ve discovered that adding :with => "value=value" to the observe_form call solves the problem: Anyone know why? Is this a rails bug? thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I have a similar problem. My form uses 3 fields: 2 selects and a text input. when I look at the params, I get the updated version of the text input but not for the selects. For these, I keep getting the last option in the list what every I do. I tried the :with thig and it didnt change anything.. anyone has an idea? Cayce Balara wrote:> Through some further research, I''ve discovered that adding > > :with => "value=value" > > to the observe_form call solves the problem: > > Anyone know why? Is this a rails bug? > > thanks. > > -- > Posted via http://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi, I too have been hitting the problem that if you omit the :updated option in the observe_form or observe_field method, then no parameters are sent. An example of the js with an update option included: (note parameters:value) new Form.EventObserver(''firstname'', function(element, value) {new Ajax.Updater(''updated_names'', ''/customer/live_lookup'', {asynchronous:true, evalScripts:true, parameters:value})}) If the :update is removed you get (note missing params): new Form.EventObserver(''firstname'', function(element, value) {new Ajax.Request(''/customer/live_lookup'', {asynchronous:true, evalScripts:true})}) Like you, I had been trying to use : with but was getting curious results. Thanks for your solution :with=>''valjue=value'' works a treat, although I dont understand why. The js it produces is: new Form.EventObserver(''firstname'', function(element, value) {new Ajax.Request(''/customer/live_lookup'', {asynchronous:true, evalScripts:true, parameters:value=value})}) In fact I cannot understand the api explanation of :with. I get the gist of what it does, but cannot fathom exactly how to use it. Can anyone offer an improved explanation of how to use :with ? Thanks Tonypm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---