Edward Trochim
2007-Mar-08 00:22 UTC
Scriptaculous Sortables: Dynamically adding a new li in the onUpdate Callback
I have two sortable lists that I can drag elements between, list A and list B. When I drag an element from A to B I want to be able to dynamically create a new element in A. I can do that just fine and call Sortable.create again for A and B to make the new element draggable. However, this is where the problem is. The two Sortable.create calls are taking place inside the onUpdate callback. So before the dragged element has settled into place in B Sortable.create has already been called on B. There isn''t a problem immediately but when I attempt to reorder the elements in B there will often be random displacements of the element being dragged around. This only happens when I call Sortable.create on list B (which it seems I need to do because if I don''t then after I call Sortable.create on list A I can no longer drag elements in list B). How can I fix this issue? Here is a screenshot showing the problem (list A on the left, list B on the right): http://paradox.mynuts.org/problem.png --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Gareth Evans
2007-Mar-08 00:43 UTC
Re: Scriptaculous Sortables: Dynamically adding a new li in the onUpdate Callback
just a guess but try storing a reference to the sortable when you create it, so you can destroy it later- calling the create method more than once will have odd effects. Gareth On 3/8/07, Edward Trochim <etrochim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I have two sortable lists that I can drag elements between, list A and > list B. When I drag an element from A to B I want to be able to > dynamically create a new element in A. I can do that just fine and > call Sortable.create again for A and B to make the new element > draggable. > > However, this is where the problem is. The two Sortable.create calls > are taking place inside the onUpdate callback. So before the dragged > element has settled into place in B Sortable.create has already been > called on B. There isn''t a problem immediately but when I attempt to > reorder the elements in B there will often be random displacements of > the element being dragged around. This only happens when I call > Sortable.create on list B (which it seems I need to do because if I > don''t then after I call Sortable.create on list A I can no longer drag > elements in list B). How can I fix this issue? > > Here is a screenshot showing the problem (list A on the left, list B > on the right): http://paradox.mynuts.org/problem.png > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Edward Trochim
2007-Mar-08 01:00 UTC
Re: Scriptaculous Sortables: Dynamically adding a new li in the onUpdate Callback
I''ve already tried that which was when I found out that calling Sortable.create on an element that is already Sortable will call Sortable.destroy on it before it is recreated. On Mar 7, 3:43 pm, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> just a guess but try storing a reference to the sortable when you create it, > so you can destroy it later- calling the create method more than once will > have odd effects. > > Gareth > > On 3/8/07, Edward Trochim <etroc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have two sortable lists that I can drag elements between, list A and > > list B. When I drag an element from A to B I want to be able to > > dynamically create a new element in A. I can do that just fine and > > call Sortable.create again for A and B to make the new element > > draggable. > > > However, this is where the problem is. The two Sortable.create calls > > are taking place inside the onUpdate callback. So before the dragged > > element has settled into place in B Sortable.create has already been > > called on B. There isn''t a problem immediately but when I attempt to > > reorder the elements in B there will often be random displacements of > > the element being dragged around. This only happens when I call > > Sortable.create on list B (which it seems I need to do because if I > > don''t then after I call Sortable.create on list A I can no longer drag > > elements in list B). How can I fix this issue? > > > Here is a screenshot showing the problem (list A on the left, list B > > on the right):http://paradox.mynuts.org/problem.png--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Kjell Bublitz
2007-Mar-08 13:07 UTC
Re: Scriptaculous Sortables: Dynamically adding a new li in the onUpdate Callback
Give the sortables a droppable and set the accept to the class of the sortable ListItems. Then use the onDrop callback to create a element and append it to the sortable beneath. If you want to know its origin you could also set a second class like "listA" to the draggable, so you can use it as reference before you append. HTH On 3/8/07, Edward Trochim <etrochim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve already tried that which was when I found out that calling > Sortable.create on an element that is already Sortable will call > Sortable.destroy on it before it is recreated. > > On Mar 7, 3:43 pm, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > just a guess but try storing a reference to the sortable when you create it, > > so you can destroy it later- calling the create method more than once will > > have odd effects. > > > > Gareth > > > > On 3/8/07, Edward Trochim <etroc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I have two sortable lists that I can drag elements between, list A and > > > list B. When I drag an element from A to B I want to be able to > > > dynamically create a new element in A. I can do that just fine and > > > call Sortable.create again for A and B to make the new element > > > draggable. > > > > > However, this is where the problem is. The two Sortable.create calls > > > are taking place inside the onUpdate callback. So before the dragged > > > element has settled into place in B Sortable.create has already been > > > called on B. There isn''t a problem immediately but when I attempt to > > > reorder the elements in B there will often be random displacements of > > > the element being dragged around. This only happens when I call > > > Sortable.create on list B (which it seems I need to do because if I > > > don''t then after I call Sortable.create on list A I can no longer drag > > > elements in list B). How can I fix this issue? > > > > > Here is a screenshot showing the problem (list A on the left, list B > > > on the right):http://paradox.mynuts.org/problem.png > > > > >-- Regards, Kjell www.m3nt0r.de --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Edward Trochim
2007-Mar-08 21:20 UTC
Re: Scriptaculous Sortables: Dynamically adding a new li in the onUpdate Callback
Can you clarify your suggestion? How would I give the sortables a droppable? And if I did that then how would appending a new element to the bottom of the sortable help (I''m assuming you mean using appendChild to the ul that is defined as sortable)? I''m just a little unclear as to what you want me to do. On Mar 8, 4:07 am, "Kjell Bublitz" <m3nt0r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Give the sortables a droppable and set the accept to the class of the > sortable ListItems. Then use the onDrop callback to create a element > and append it to the sortable beneath. If you want to know its origin > you could also set a second class like "listA" to the draggable, so > you can use it as reference before you append. > > HTH > > On 3/8/07, Edward Trochim <etroc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''ve already tried that which was when I found out that calling > > Sortable.create on an element that is already Sortable will call > > Sortable.destroy on it before it is recreated. > > > On Mar 7, 3:43 pm, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > just a guess but try storing a reference to the sortable when you create it, > > > so you can destroy it later- calling the create method more than once will > > > have odd effects. > > > > Gareth > > > > On 3/8/07, Edward Trochim <etroc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have two sortable lists that I can drag elements between, list A and > > > > list B. When I drag an element from A to B I want to be able to > > > > dynamically create a new element in A. I can do that just fine and > > > > call Sortable.create again for A and B to make the new element > > > > draggable. > > > > > However, this is where the problem is. The two Sortable.create calls > > > > are taking place inside the onUpdate callback. So before the dragged > > > > element has settled into place in B Sortable.create has already been > > > > called on B. There isn''t a problem immediately but when I attempt to > > > > reorder the elements in B there will often be random displacements of > > > > the element being dragged around. This only happens when I call > > > > Sortable.create on list B (which it seems I need to do because if I > > > > don''t then after I call Sortable.create on list A I can no longer drag > > > > elements in list B). How can I fix this issue? > > > > > Here is a screenshot showing the problem (list A on the left, list B > > > > on the right):http://paradox.mynuts.org/problem.png > > -- > Regards, Kjellwww.m3nt0r.de--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---