Can jQuery UI Sortable handle complex selectors for item options?

I have list items in an unordered list that, when double-clicked, can be edited using the wysiwyg editor.

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

My goal is to prevent the sorting of the list item while it is being edited - otherwise, once the form element has been replaced in place of the content.

Unfortunately, my selector for elements does not work. Is sorting capable of handling complex selectors like these? If not, are there other smart tools to disconnect some items from sorting, perhaps a callback function?

I would rather rely on this sortable option, since the wysiwyg plugin is deeply nested jEditable and, as far as I know, does not open any events for me.

Using jQuery 1.4.2 and jQuery UI 1.8.1

+3
source share
1 answer

The jQuery UI Sortable accepts any selector, but the selector is used to select which elements are sorted when sorting, and not when dragging starts. If you change the DOM, it still remembers which elements were sorted when the sort was created.

You should be able to return falseout sortstartif ui.itemincludes <form>, but now it does not work; instead, you can use this, which does:

$('ul').sortable({
  items: '> li',
  cancel: 'li:has(form)'
});
+3
source

Source: https://habr.com/ru/post/1747289/


All Articles