Titou Titou
2007-May-03 12:56 UTC
update_element_function + sortable_element = how to update ?
Hi. I''ve realised this example and it works great : http://demo.script.aculo.us/ajax/sortable_elements But i want to add to the user the capability to add items to the sortable list. Here is my code : ####################### #list_controller.rb : ####################### class ListController < ApplicationController def index @elements = ["toto", "titi", "tata", "riri", "fifi", "loulou"] end def order @order = params[:list] render :partial => ''list'' end end ####################### #index.rhtml : ####################### <div id="choix_elements"> <% i = 7 %> <% @elements.each do |elt| %> <span id="<%= elt %>" onclick="<%update_element_function(''list'', :position => :bottom, :content => "<li id=''item_#{i}''>#{elt}</li>") %>"> <%= elt %> </span> <% i += 1 %> <% end %> </div> <ul id="list"> <% 6.times do |i| -%> <li id="item_<%= i+1 %>">I''m number <%= i+1 %></li> <% end -%> </ul> <p id="list-info"></p> <%= sortable_element ''list'', :update => ''list-info'', :complete => visual_effect(:highlight, ''list''), :url => { :action => "order" } %> ####################### #_list.rhtml ####################### Updated order is: <%= @order.join('', '') %>. The trouble is that added elements couldn''t be sorted. Is there a way to "refresh" the sortable_element method please ? Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Curtis Edmond
2007-May-03 14:44 UTC
Re: update_element_function + sortable_element = how to update ?
What I would do is on your index.rhtml page, add a remote_form_for that takes in a new element and submits it to a "add_element" action in your controller. The, via an RJS file or just inline in the controller (via render :update) I''d replace_html on the dom element that holds your list. Curtis Edmond http://www.okwithfailure.com On May 3, 5:56 am, Titou Titou <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi. > > I''ve realised this example and it works great :http://demo.script.aculo.us/ajax/sortable_elements > > But i want to add to the user the capability to add items to the > sortable list. > > Here is my code : > > ####################### > #list_controller.rb : > ####################### > > class ListController < ApplicationController > def index > @elements = ["toto", "titi", "tata", "riri", "fifi", "loulou"] > end > > def order > @order = params[:list] > render :partial => ''list'' > end > end > > ####################### > #index.rhtml : > ####################### > > <div id="choix_elements"> > <% i = 7 %> > <% @elements.each do |elt| %> > <span id="<%= elt %>" onclick="<%> update_element_function(''list'', :position => :bottom, :content => "<li > id=''item_#{i}''>#{elt}</li>") %>"> > <%= elt %> > </span> > <% i += 1 %> > <% end %> > </div> > > <ul id="list"> > <% 6.times do |i| -%> > <li id="item_<%= i+1 %>">I''m number <%= i+1 %></li> > <% end -%> > </ul> > > <p id="list-info"></p> > > <%= sortable_element ''list'', > :update => ''list-info'', > :complete => visual_effect(:highlight, ''list''), > :url => { :action => "order" } %> > > ####################### > #_list.rhtml > ####################### > > Updated order is: <%= @order.join('', '') %>. > > The trouble is that added elements couldn''t be sorted. Is there a way to > "refresh" the sortable_element method please ? > > Thanks in advance. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Titou Titou
2007-May-03 15:39 UTC
Re: update_element_function + sortable_element = how to upda
Curtis Edmond wrote [...] Thanks a lot :) i wanted to avoid server requests, but i think i''ll do as you said, i''ve not found any other solution ;) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---