Asa Hopkins
2006-Apr-03 00:28 UTC
[Rails] 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_''+@account.id.to_s, :frequency => 0.5, :update => ''auto_complete_''+@account.id.to_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 -- Posted via http://www.ruby-forum.com/.
daniel wiesmann
2006-Apr-03 10:13 UTC
[Rails] Re: problems with Rails 1.1 observe_field :with serialized
Asa Hopkins wrote:> 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_''+@account.id.to_s, :frequency => 0.5, > :update => ''auto_complete_''+@account.id.to_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, 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 Hopkins
2006-Apr-03 15:20 UTC
[Rails] Re: problems with Rails 1.1 observe_field :with serialized
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 Hopkins 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-- Posted via http://www.ruby-forum.com/.
Asa Hopkins
2006-Apr-03 17:43 UTC
[Rails] Re: problems with Rails 1.1 observe_field :with serialized
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 Hopkins 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 Hopkins 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-- Posted via http://www.ruby-forum.com/.
Andy Shen
2006-Apr-04 13:35 UTC
[Rails] Re: problems with Rails 1.1 observe_field :with serialized
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. On 4/4/06, Asa Hopkins <asa@caltech.edu> wrote:> 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 Hopkins 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 Hopkins 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Asa Hopkins
2006-Apr-04 15:33 UTC
[Rails] Re: Re: problems with Rails 1.1 observe_field :with serializ
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.-- Posted via http://www.ruby-forum.com/.
alexander
2006-Apr-05 17:21 UTC
[Rails] Re: problems with Rails 1.1 observe_field :with serialized
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 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. > > On 4/4/06, Asa Hopkins <asa@caltech.edu> wrote: > >>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 Hopkins 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 Hopkins 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 >> >> >>-- >>Posted via http://www.ruby-forum.com/. >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails