laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-01 16:10 UTC
JS error when adding/removing items on a form
Hi, I''m getting a Javascript error using tried and true RailsCast code! I''m submitting a single form for one object (ec_order), which has many of another object (ec_line_item) within it. I have links to add and remove items in the form. Here is the view: <% form_for :ec_order, :url => ''summary'' do |f| %> <table> <tr> <td>Item</td> <td></td> </tr> <tr><td> <table cellpadding="0" cellspacing="0" border="0"> <tr><td> <div id="ec_line_items"> <%= render :partial => ''ec_line_item'', :collection => @ec_order.ec_line_items %> </div> <%= add_prescription_link "Add a prescription" %> </td></tr> </table> </td></tr> <tr><td align="center"><%= submit_tag("Submit Form") %></td></ tr> </table> <% end %> and here is the partial <div class="ec_line_item"> <% fields_for "ec_order[ec_line_item_attributes][]", ec_line_item do |ec_line_item_form| %> <tr><td> <table> <tr> <td><%= ec_line_item_form.text_field :prescription_number %></td> <td><%= ec_line_item_form.text_field :description %></td> <td><%= link_to_function "remove", "this.up(''.ec_line_item'').remove()" %></td> </tr> <tr> <td align="center">Prescription Number</td> <td align="center">Description</td> <td></td> </tr> </table> </td></tr> <% end %> </div> When I click on the "remove" link I get the JS error "this.up(".ec_line_item") has no properties". Any ideas what I''m doing wrong? - Dave --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
I suspect that the problem is that up is a method on the prototype- extended Element ''class''. The examples in the api suggest this -- $ (''some_dom_id'').up() -- the dollar-sign function extends the object as required. Have you tried something like $(this).up(".ec_line_item").remove() On Feb 1, 11:10 am, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I''m getting a Javascript error using tried and true RailsCast code! > I''m submitting a single form for one object (ec_order), which has many > of another object (ec_line_item) within it. I have links to add and > remove items in the form. Here is the view: > > <% form_for :ec_order, :url => ''summary'' do |f| %> > <table> > <tr> > <td>Item</td> > <td></td> > </tr> > <tr><td> > <table cellpadding="0" cellspacing="0" border="0"> > <tr><td> > <div id="ec_line_items"> > <%= render :partial => > ''ec_line_item'', :collection => @ec_order.ec_line_items %> > </div> > <%= add_prescription_link "Add a > prescription" %> > </td></tr> > </table> > </td></tr> > <tr><td align="center"><%= submit_tag("Submit Form") %></td></ > tr> > </table> > <% end %> > > and here is the partial > > <div class="ec_line_item"> > <% fields_for "ec_order[ec_line_item_attributes][]", > ec_line_item do |ec_line_item_form| %> > <tr><td> > <table> > <tr> > <td><%= ec_line_item_form.text_field :prescription_number > %></td> > <td><%= ec_line_item_form.text_field :description %></td> > <td><%= link_to_function "remove", > "this.up(''.ec_line_item'').remove()" %></td> > </tr> > <tr> > <td align="center">Prescription Number</td> > <td align="center">Description</td> > <td></td> > </tr> > </table> > </td></tr> > <% end %> > </div> > > When I click on the "remove" link I get the JS error > "this.up(".ec_line_item") has no properties". Any ideas what I''m > doing wrong? - Dave--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-01 19:44 UTC
Re: JS error when adding/removing items on a form
I tried this as well and got the error "$(this).up(".ec_line_item") has no properties" Thanks though, - Dave On Feb 1, 10:35 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> I suspect that the problem is that up is a method on the prototype- > extended Element ''class''. The examples in the api suggest this -- $ > (''some_dom_id'').up() -- the dollar-sign function extends the object as > required. > > Have you tried something like $(this).up(".ec_line_item").remove() > > On Feb 1, 11:10 am, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" > > > > <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote: > > Hi, > > > I''m getting a Javascript error using tried and true RailsCast code! > > I''m submitting a single form for one object (ec_order), which has many > > of another object (ec_line_item) within it. I have links to add and > > remove items in the form. Here is the view: > > > <% form_for :ec_order, :url => ''summary'' do |f| %> > > <table> > > <tr> > > <td>Item</td> > > <td></td> > > </tr> > > <tr><td> > > <table cellpadding="0" cellspacing="0" border="0"> > > <tr><td> > > <div id="ec_line_items"> > > <%= render :partial => > > ''ec_line_item'', :collection => @ec_order.ec_line_items %> > > </div> > > <%= add_prescription_link "Add a > > prescription" %> > > </td></tr> > > </table> > > </td></tr> > > <tr><td align="center"><%= submit_tag("Submit Form") %></td></ > > tr> > > </table> > > <% end %> > > > and here is the partial > > > <div class="ec_line_item"> > > <% fields_for "ec_order[ec_line_item_attributes][]", > > ec_line_item do |ec_line_item_form| %> > > <tr><td> > > <table> > > <tr> > > <td><%= ec_line_item_form.text_field :prescription_number > > %></td> > > <td><%= ec_line_item_form.text_field :description %></td> > > <td><%= link_to_function "remove", > > "this.up(''.ec_line_item'').remove()" %></td> > > </tr> > > <tr> > > <td align="center">Prescription Number</td> > > <td align="center">Description</td> > > <td></td> > > </tr> > > </table> > > </td></tr> > > <% end %> > > </div> > > > When I click on the "remove" link I get the JS error > > "this.up(".ec_line_item") has no properties". Any ideas what I''m > > doing wrong? - Dave- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---