# AJAX/RJS issue: observe\_form not passing in form params

**URL:** <https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969>\
**Category:** Rails\
**Created:** [September 17, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969 "2006-09-17T18:04:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [September 17, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969/1 "2006-09-17T18:04:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [September 17, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969/2 "2006-09-17T18:12:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [September 30, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969/3 "2006-09-30T20:26:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [October 24, 2006, 1:04pm UTC](https://www.ruby-forum.com/t/ajax-rjs-issue-observe-form-not-passing-in-form-params/68969/4 "2006-10-24T13:04:45Z")

</div>

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
