Samuel Dionne-Riel
2005-Aug-18 13:11 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
Maybe a newb question, maybe not. It''s not well documented, and I want to know how to know the id of my newly dropped item. The usage, would be to attach the newly dropped id to its *new* parent in a DB. Thanks. ???????????????????????? http://www.samueldr.com http://www.hostingquebec.ca
Nic Schlueter
2005-Aug-18 16:41 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
I believe you want to use one of the callbacks (onChange or onUpdate). These callbacks are documented here: http://wiki.script.aculo.us/scriptaculous/show/Sortable.create I believe you define a call back by passing this: onUpdate: function(element){//method definition} as and additional option The element that is passed through is the entire <ul>...</ul> as it appears after the update/change. So in order to get to the element that was dropped you are going to need to write some (quite a bit?) javascript in the call back. If I am misunderstanding you problem or you need more help let me know. Nicholas On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com> wrote:> > Maybe a newb question, maybe not. > It''s not well documented, and I want to know how to know the id of my > newly dropped item. > The usage, would be to attach the newly dropped id to its *new* parent in > a DB. > > Thanks. > > ???????????????????????? > http://www.samueldr.com > http://www.hostingquebec.ca > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Samuel Dionne-Riel
2005-Aug-18 16:46 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
Hi, thanks for your help. I haven''t tested it yet, but the 2 answers are confusing me... There is another one who said :> onDrop: function(element) > { > deleteImage(element.id); } > });I think that the onDrop is good only on draggable, but isn''t a sortable''s child a draggable ?!? And, onChange is too much, it''s not on drop, it''s on ANY change, too much change when moving freely the item. onUpdate returns the container (duh) I think that it should return TOO the dropped item, it could be really good. Thanks again, and future thanks !> I believe you want to use one of the callbacks (onChange or onUpdate). > These callbacks are documented here: > http://wiki.script.aculo.us/scriptaculous/show/Sortable.create > > I believe you define a call back by passing this: > onUpdate: function(element){//method definition} > as and additional option > > The element that is passed through is the entire <ul>...</ul> as it > appears after the update/change. So in order to get to the element > that was dropped you are going to need to write some (quite a bit?) > javascript in the call back. > > If I am misunderstanding you problem or you need more help let me know. > Nicholas > > On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com> wrote: >> >> Maybe a newb question, maybe not. >> It''s not well documented, and I want to know how to know the id of my >> newly dropped item. >> The usage, would be to attach the newly dropped id to its *new* parent >> in >> a DB. >> >> Thanks. >> >> ???????????????????????? >> http://www.samueldr.com >> http://www.hostingquebec.ca >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >???????????????????????? http://www.samueldr.com http://www.hostingquebec.ca
Ed C.
2005-Aug-18 17:06 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
Sam, In the past, to get the dropped item, I wrote the following code: <script type="text/javascript"> function getIndex(li) { var items = li.parentNode.childNodes; //get list for(var i = 0; i < items.length; i++) { //traverse list if(li == items[i]) { //look for match alert(i); //display position (0-based) break; } } } </script> <ul id="parentList"> <li id="childItem_1" onmouseup="getIndex(this);">item 1</li> <li id="childItem_2" onmouseup="getIndex(this);">item 2</li> <li id="childItem_3" onmouseup="getIndex(this);">item 3</li> </ul> (I actually do this via Behaviour, but you get the point.) On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com> wrote:> > Hi, > thanks for your help. > > I haven''t tested it yet, but the 2 answers are confusing me... > > There is another one who said : > > onDrop: function(element) > > { > > deleteImage(element.id <http://element.id>); } > > }); > > I think that the onDrop is good only on draggable, but isn''t a sortable''s > child a draggable ?!? > > And, onChange is too much, it''s not on drop, it''s on ANY change, too much > change when moving freely the item. > > onUpdate returns the container (duh) I think that it should return TOO the > dropped item, it could be really good. > > Thanks again, and future thanks ! > > > I believe you want to use one of the callbacks (onChange or onUpdate). > > These callbacks are documented here: > > http://wiki.script.aculo.us/scriptaculous/show/Sortable.create > > > > I believe you define a call back by passing this: > > onUpdate: function(element){//method definition} > > as and additional option > > > > The element that is passed through is the entire <ul>...</ul> as it > > appears after the update/change. So in order to get to the element > > that was dropped you are going to need to write some (quite a bit?) > > javascript in the call back. > > > > If I am misunderstanding you problem or you need more help let me know. > > Nicholas > > > > On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com> wrote: > >> > >> Maybe a newb question, maybe not. > >> It''s not well documented, and I want to know how to know the id of my > >> newly dropped item. > >> The usage, would be to attach the newly dropped id to its *new* parent > >> in > >> a DB. > >> > >> Thanks. > >> > >> ???????????????????????? > >> http://www.samueldr.com > >> http://www.hostingquebec.ca > >> > >> _______________________________________________ > >> Rails-spinoffs mailing list > >> Rails-spinoffs@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > >> > > > > > ???????????????????????? > http://www.samueldr.com > http://www.hostingquebec.ca > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20050818/c4544e9c/attachment-0001.html
Nic Schlueter
2005-Aug-18 17:17 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
This is pretty clever. Good tip Ed. I also tried to test the onDrop functionality and it doesn''t look like Sortable.create propagates that option down to the draggable elements. Nicholas On 8/18/05, Ed C. <defeated2k4@gmail.com> wrote:> Sam, > > In the past, to get the dropped item, I wrote the following code: > > <script type="text/javascript"> > function getIndex(li) { > var items = li.parentNode.childNodes; //get list > for(var i = 0; i < items.length; i++) { //traverse list > if(li == items[i]) { //look for match > alert(i); //display position (0-based) > break; > } > } > } > </script> > > <ul id="parentList"> > <li id="childItem_1" onmouseup="getIndex(this);">item > 1</li> > <li id="childItem_2" onmouseup="getIndex(this);">item > 2</li> > <li id="childItem_3" onmouseup="getIndex(this);">item > 3</li> > </ul> > > (I actually do this via Behaviour, but you get the point.) > > > On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com > wrote: > > Hi, > > thanks for your help. > > > > I haven''t tested it yet, but the 2 answers are confusing me... > > > > There is another one who said : > > > onDrop: function(element) > > > { > > > deleteImage(element.id); } > > > }); > > > > I think that the onDrop is good only on draggable, but isn''t a sortable''s > > child a draggable ?!? > > > > And, onChange is too much, it''s not on drop, it''s on ANY change, too much > > change when moving freely the item. > > > > onUpdate returns the container (duh) I think that it should return TOO the > > dropped item, it could be really good. > > > > Thanks again, and future thanks ! > > > > > I believe you want to use one of the callbacks (onChange or onUpdate). > > > These callbacks are documented here: > > > > http://wiki.script.aculo.us/scriptaculous/show/Sortable.create > > > > > > I believe you define a call back by passing this: > > > onUpdate: function(element){//method definition} > > > as and additional option > > > > > > The element that is passed through is the entire <ul>...</ul> as it > > > appears after the update/change. So in order to get to the element > > > that was dropped you are going to need to write some (quite a bit?) > > > javascript in the call back. > > > > > > If I am misunderstanding you problem or you need more help let me know. > > > Nicholas > > > > > > On 8/18/05, Samuel Dionne-Riel < samueldr@samueldr.com> wrote: > > >> > > >> Maybe a newb question, maybe not. > > >> It''s not well documented, and I want to know how to know the id of my > > >> newly dropped item. > > >> The usage, would be to attach the newly dropped id to its *new* parent > > >> in > > >> a DB. > > >> > > >> Thanks. > > >> > > >> ???????????????????????? > > >> http://www.samueldr.com > > >> http://www.hostingquebec.ca > > >> > > >> _______________________________________________ > > >> Rails-spinoffs mailing list > > >> Rails-spinoffs@lists.rubyonrails.org > > >> > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >> > > > > > > > > > ???????????????????????? > > http://www.samueldr.com > > http://www.hostingquebec.ca > > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >
Samuel Dionne-Riel
2005-Aug-18 17:24 UTC
[Rails-spinoffs] Sortable > how to know wich elementID was dropped ?
Yeah, good, gonna try it soon.> This is pretty clever. Good tip Ed. > > I also tried to test the onDrop functionality and it doesn''t look like > Sortable.create propagates that option down to the draggable elements. > > Nicholas > > On 8/18/05, Ed C. <defeated2k4@gmail.com> wrote: >> Sam, >> >> In the past, to get the dropped item, I wrote the following code: >> >> <script type="text/javascript"> >> function getIndex(li) { >> var items = li.parentNode.childNodes; //get list >> for(var i = 0; i < items.length; i++) { //traverse list >> if(li == items[i]) { //look for match >> alert(i); //display position (0-based) >> break; >> } >> } >> } >> </script> >> >> <ul id="parentList"> >> <li id="childItem_1" onmouseup="getIndex(this);">item >> 1</li> >> <li id="childItem_2" onmouseup="getIndex(this);">item >> 2</li> >> <li id="childItem_3" onmouseup="getIndex(this);">item >> 3</li> >> </ul> >> >> (I actually do this via Behaviour, but you get the point.) >> >> >> On 8/18/05, Samuel Dionne-Riel <samueldr@samueldr.com > wrote: >> > Hi, >> > thanks for your help. >> > >> > I haven''t tested it yet, but the 2 answers are confusing me... >> > >> > There is another one who said : >> > > onDrop: function(element) >> > > { >> > > deleteImage(element.id); } >> > > }); >> > >> > I think that the onDrop is good only on draggable, but isn''t a >> sortable''s >> > child a draggable ?!? >> > >> > And, onChange is too much, it''s not on drop, it''s on ANY change, too >> much >> > change when moving freely the item. >> > >> > onUpdate returns the container (duh) I think that it should return TOO >> the >> > dropped item, it could be really good. >> > >> > Thanks again, and future thanks ! >> > >> > > I believe you want to use one of the callbacks (onChange or >> onUpdate). >> > > These callbacks are documented here: >> > > >> http://wiki.script.aculo.us/scriptaculous/show/Sortable.create >> > > >> > > I believe you define a call back by passing this: >> > > onUpdate: function(element){//method definition} >> > > as and additional option >> > > >> > > The element that is passed through is the entire <ul>...</ul> as it >> > > appears after the update/change. So in order to get to the element >> > > that was dropped you are going to need to write some (quite a bit?) >> > > javascript in the call back. >> > > >> > > If I am misunderstanding you problem or you need more help let me >> know. >> > > Nicholas >> > > >> > > On 8/18/05, Samuel Dionne-Riel < samueldr@samueldr.com> wrote: >> > >> >> > >> Maybe a newb question, maybe not. >> > >> It''s not well documented, and I want to know how to know the id of >> my >> > >> newly dropped item. >> > >> The usage, would be to attach the newly dropped id to its *new* >> parent >> > >> in >> > >> a DB. >> > >> >> > >> Thanks. >> > >> >> > >> ???????????????????????? >> > >> http://www.samueldr.com >> > >> http://www.hostingquebec.ca >> > >> >> > >> _______________________________________________ >> > >> Rails-spinoffs mailing list >> > >> Rails-spinoffs@lists.rubyonrails.org >> > >> >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > >> >> > > >> > >> > >> > ???????????????????????? >> > http://www.samueldr.com >> > http://www.hostingquebec.ca >> > >> > _______________________________________________ >> > Rails-spinoffs mailing list >> > Rails-spinoffs@lists.rubyonrails.org >> > >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > >> >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> >> >???????????????????????? http://www.samueldr.com http://www.hostingquebec.ca