Forum: Ruby on Rails problems with Rails 1.1 observe_field :with serialized

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Asa H. (Guest)
on 2006-04-03 04:28
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_'removed_email_address@domain.invalid_s, 
:frequency => 0.5,
		         :update => 'auto_complete_'removed_email_address@domain.invalid_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
daniel wiesmann (Guest)
on 2006-04-03 14:15
(Received via mailing list)
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
Asa H. (Guest)
on 2006-04-03 19:20
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
Asa H. (Guest)
on 2006-04-03 21:43
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
Andy Shen (Guest)
on 2006-04-04 17:38
(Received via mailing list)
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.
Asa H. (Guest)
on 2006-04-04 19:33
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.
alexander (Guest)
on 2006-04-05 21:23
(Received via mailing list)
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
This topic is locked and can not be replied to.