Problems with Rails 1.1 observe_field :with serialized

I’d like to use observe_field to watch a field, and then when it changes
send the entire form to the server. I had been using

<%= observe_field 'entity_name_'[email protected]_s, :frequency => 0.5,
:update => 'auto_complete_'[email protected]_s, :url =>
{ :controller => ‘committees’, :action=>
‘auto_complete_for_entity_name’,:params=>{:committee_id=>@committee.id}
}, :with => ‘Form.serialize(“new_contrib_form_#{@account.id.to_s}”)’ %>

But the problem appears to be that when this is made into Javascript, it
wants to do something like

parameters:‘Form.serialize(‘search_form’)=’+value

It used to work fine and give me

parameters:Form.serialize(‘search_form’)

I’m pretty sure the same thing happens with observe_form. Ideas?

Thanks,
Asa

Asa H. wrote:

wants to do something like
Asa

Asa,

It seemed to work for me after I removed the quotes from the form being
observed.
I changed from
Form.serialize(‘form_name’)
to
Form.serialize(form_name)
and it worked again as before…

Daniel

That doesn’t work for me. What happens is that the parameters passed
look like

Parameters: {“Form.serialize(new_contrib_form_13)”=>“A”,
“action”=>“auto_complete_for_entity_name”, “controller”=>“committees”,
“committee_id”=>“1”}

The relevant (new for 1.1) section of the API says:

:with: A JavaScript expression specifying the parameters for the
XMLHttpRequest. This defaults to â??valueâ??, which in the evaluated context
refers to the new field value. If you specify a string without a “=”,
itâ??ll be extended to mean the form key that the value should be assigned
to. So :with => “term” gives “â??termâ??=value”. If a “=” is present, no
extension will happen.

The problem is in the adding of the equals sign, etc. It’s trying to do
too much work for me.

Asa

daniel wiesmann wrote:

Asa H. wrote:

wants to do something like
Asa

Asa,

It seemed to work for me after I removed the quotes from the form being
observed.
I changed from
Form.serialize(‘form_name’)
to
Form.serialize(form_name)
and it worked again as before…

Daniel

OK. I seem to have gotten it working again, but the solution seems like
a total hack.

:with => “foo = Form.serialize(‘new_contrib_form_#{@account.id.to_s}’)”

Including the = sign in the :with tag prevents it from rewriting with
‘=value’ at the end. However, the “foo =” part doesn’t matter at all,
except that it’s a valid statement. I see nothing about anything called
“foo” on the Rails side. I do, however, get the whole form into
params[] as I would like. So, it works, but feels shaky.

Asa

Asa H. wrote:

That doesn’t work for me. What happens is that the parameters passed
look like

Parameters: {“Form.serialize(new_contrib_form_13)”=>“A”,
“action”=>“auto_complete_for_entity_name”, “controller”=>“committees”,
“committee_id”=>“1”}

The relevant (new for 1.1) section of the API says:

:with: A JavaScript expression specifying the parameters for the
XMLHttpRequest. This defaults to â??valueâ??, which in the evaluated context
refers to the new field value. If you specify a string without a “=”,
itâ??ll be extended to mean the form key that the value should be assigned
to. So :with => “term” gives “â??termâ??=value”. If a “=” is present, no
extension will happen.

The problem is in the adding of the equals sign, etc. It’s trying to do
too much work for me.

Asa

daniel wiesmann wrote:

Asa H. wrote:

wants to do something like
Asa

Asa,

It seemed to work for me after I removed the quotes from the form being
observed.
I changed from
Form.serialize(‘form_name’)
to
Form.serialize(form_name)
and it worked again as before…

Daniel

yep, I can confirm the same thing is happening with observe_form in my
app and your work around fixes it.

But would be nice to not have to do that I suppose.

observe_form apparently defaults to sending the whole form, so for it
you can just leave off :with completely, and it’ll work.

Asa

Andy Shen wrote:

yep, I can confirm the same thing is happening with observe_form in my
app and your work around fixes it.

But would be nice to not have to do that I suppose.

hi there.
i had the same problem in an app where one dev used observe_fields
(little code snippet from the rails wiki)
the workaround didn´t work for me so i went ahead and just changed the
source of the prototype_helper and took out the part where it adds the =

  • value stuff.
    its in
    gems/actionpack-1.12.0/lib/action_view/helpers/prototype_helper.rb
    in the function build_observer
    just thought i´d mention that as another quick fix.
    kind regards,
    a