Forum: Ruby on Rails Ajax sortable_element refresh

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.
4184124738873c21d5435fd4ef60d7df?d=identicon&s=25 hpacheco (Guest)
on 2007-05-29 06:36
(Received via mailing list)
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
<html>
  <head>
    <title>Ajax List Demo</title>
    <%= javascript_include_tag :defaults %>
  </head>
  <body>
    <%= 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 %>

  <ul id="list">
    <% 6.times do |i| -%>
    <li id="item_<%= i+1 %>">I'm number <%= i+1 %></li>
    <% end -%>
  </ul>

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

  </body>
</html>

### Controller

def index
end

def add_item
  render_text "<li id=\"item_7" + "\">I'm number 7</li>"
end
This topic is locked and can not be replied to.