Serializing sortables

Serializing sortables


Hi all, I'm having some trouble using the 'serialize' function for the
sortable elements.
It looks like the 'update' callback is called before removing the
helper element from the list.
If you want to get the list order in the update callback you'll end up
with an extra element in the list (the helper):
$('#mylist').sortable({
update: function(e, ui) {
console.debug($(this).sortable('serialize'));
/* $.ajax(... */
}
});
I also find quite useless the string returned from the 'serialize'
command:
"my-entry[]=1my-entry[]=4my-entry[]=5my-entry[]=6my-entry[]=3my-
entry[]=5"
(PS. my-entry-5 is repeated twice since the last one is the helper,
see above)
My suggestion is to return an array instead.
Right now to serialize the list I use this function:
$('#mylist').sortable({
update: function(e, ui) {
var helper = ui.helper.get(0);
var list_order = [];
$(this).children().each(function() {
/* filtering out the helper element */
if (this !== helper)
list_order.push(this.id.split('-').pop());
});
$.ajax({
url: 'change_order', data: { 'items[]': list_order }
});
}
});
--
Federico.