views:

130

answers:

1

I have list items in an unordered list that when double clicked, can be edited in place via a wysiwyg editor.

$('ul.mtm_section').sortable({
  disabled: true,
  distance: 10,
  items: '> li:not(:has(form))'
});

My goal is to prevent the list item from being sorted while it is being edited - aka once a form element has been swapped in place of the contents.

Unfortunately my selector for items is not working. Is sortable able to handle complex selectors like these? If not, are there other clever means to disable some items from being sortable, perhaps a callback function?

I would prefer to rely on this sortable option, as the wysiwyg plugin is deeply nested with jEditable and as far as I know does not open up any events for me to hook into.

Using jQuery 1.4.2 and jQuery UI 1.8.1

+2  A: 

jQuery UI Sortable accepts any selector, but the selector is used to choose which items are sortable when the sortable is created—not when a drag starts. If you change the DOM, it will still remember which items were sortable when the sortable was created.

You should be able to return false from sortstart if ui.item contains a <form>, but this seems to not work right now; instead, you can use this, which does:

$('ul').sortable({
  items: '> li',
  cancel: 'li:has(form)'
});
snover
Thanks! I knew about cancel, but I must've had a bug in my code when I tried it. This is working for me.As a side note, I wonder if there are other instances where sortable would benefit from an option that forced the sortable to use "live" jquery event hooks, with an option such as liveItemsSelector: true
jverdi