script.aculo.us: onUpdate in Sortable.create

84 views
Skip to first unread message

Louis W

unread,
Nov 2, 2007, 11:18:49 AM11/2/07
to Ruby on Rails: Spinoffs
Can't seem to get the onUpdate to work in for a sortable list. I am
following the documentation and the included functional tests but
nothing is firing for me. Any idea why?


Sortable.create('list1', {
tree:true
, onUpdate:function(sortable){
alert('onUpdate')
}
, handle: 'handle'
, scroll:window
, only:'drag'
});


I'm running Prototype 1.5.1.1 and Scriptaculous 1.7.1_beta3

Chris

unread,
Nov 16, 2007, 8:04:20 AM11/16/07
to Ruby on Rails: Spinoffs
I had the same problem, and the issue is probably in your markup. Each
item of the 'sortable' has to be named in the format 'string_integer'.
So this will work:

<ul id="makeMeSortable">
<li id="item_1"></li>
<li id="item_2"></li>
<li id="item_3"></li>
</ul>

and this will NOT work:

<ul id="makeMeSortable">
<li id="firstitem"></li>
<li id="seconditem"></li>
<li id="thirditem"></li>
</ul>

The items will still drag if they are not properly id'ed, but the
onUpdate and onChange events will not fire.

This drove me crazy for 3 days. I hope I can save you a similar
headache.

-Chris

c h r i s AT u n t r o d DOT c o m

Tobie Langel

unread,
Nov 16, 2007, 8:14:19 AM11/16/07
to Ruby on Rails: Spinoffs
You can easily customize this by resetting (in your own js file) the
Sortable.SERIALIZE_RULE to something else than
/^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/

Regards,

Tobie

Surendra

unread,
Nov 22, 2007, 9:56:31 AM11/22/07
to rubyonrail...@googlegroups.com
Another thing which I just discovered is that, the element needs to have an id.
So, if you try to make below ul sortable, it won't work.
Sortable.options function is going to boomerang.
Can't think of a neat solution to fix this, till then it is something
to be careful about.

<ul >


<li id="item_1"></li>
<li id="item_2"></li>
<li id="item_3"></li>
</ul>

-Surendra

--
Surendra Singhi
http://ssinghi.kreeti.com, http://www.kreeti.com

Reply all
Reply to author
Forward
0 new messages