Ajax sortable_element refresh


#1

Hi,

I have the following ajax example, with a list of counters, and two
buttons for adding/removing elements. The list is sortable.

There are two things that I don’t know how to do:
. remove an elemet
. when I add a new element to the list, that element doesn’t become
sortable with the rest of the list

Thanks,
hugo

View

Ajax List Demo <%= javascript_include_tag :defaults %> <%= form_remote_tag(:update => "list", :url => { :action => :add_item }, :position => "bottom" ) %>
  <%= text_field_tag :newitem %>
  <%= submit_tag "Add item" %>
<%= end_form_tag %>

<%= form_remote_tag(:delete => “list”,
:url => { :action => :cyaitem }) %>

  <%= text_field_tag :cyaitem %>
  <%= submit_tag "Remove item" %>
<%= end_form_tag %>
    <% 6.times do |i| -%>
  • I'm number <%= i+1 %>
  • <% end -%>

<%= sortable_element ‘list’, :complete => visual_effect(:highlight,
‘list’) %>

Controller

def index
end

def add_item
render_text “<li id=“item_7” + “”>I’m number 7”
end