Re: changing values when sorting

Christophe Porteneuve
2006-09-28T06:38:32Z

frank a écrit :
> I''m not sure if this can be done, but I though I would ask. Lets
say I
> have two sortable lists in which items can be moved back and forth. One
> list has some numbers, while the other one is empty. Once moved from
> list A to list B, I want the value of the number to increase by one,
> and when moved back, I want it to decrease by one. I was think of using
> onUpdate, but I don''t see how I could make that work. I''m
using PHP by
> the way.

Your onUpdate event handler (which is only triggered when the contained
items actually changed, btw) for each list will receive your container
as an argument.  You may then iterate through its contained items
(Prototype provides plenty of helpers there) to look for the new one,
and depending on the list you''re reacting to, either add or subtract
from its number.

To identify an item as the "new one" though, you''ll probably
need to use
custom properties on the DOM nodes for the items.  script.aculo.us does
not provide the changed item as an argument.

*Therefore* look into the onChange event handler, which is called
whenever the elements'' order changes, and receives the *changed
element*
as an argument.  However, this will be triggered for in-list reordering
as well.

''HTH

--
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org