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| %>

Item
<%= render :partial => 'ec_line_item', :collection => @ec_order.ec_line_items %>
<%= add_prescription_link "Add a prescription" %>
<%= submit_tag("Submit Form") %>
<% end %>

and here is the partial

<% fields_for "ec_order[ec_line_item_attributes][]", ec_line_item do |ec_line_item_form| %>
<%= ec_line_item_form.text_field :prescription_number %> <%= ec_line_item_form.text_field :description %> <%= link_to_function "remove", "this.up('.ec_line_item').remove()" %>
Prescription Number Description
<% end %>

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

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, “[email protected]

I tried this as well and got the error “$(this).up(”.ec_line_item")
has no properties"

Thanks though, - Dave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs