I don't want to allow a ul
's li
s to be sortable if there is one or more elements with the class unsaved
inside it. How to achieve this?
Psuedo code:
var $my_list = $('#my-list');
$my_list.sortable({
start: function() {
if($('.unsaved', $my_list).length) {
// DONOT ALLOW SORTING
} else {
// OK GO AHEAD AND SORT ALL YOU WANT
}
}
});
$my_list.disableSelection();
Edit
Sorry I should have been more clear. I can't just do a check to see if elements with the class unsaved
exists before apply the sortable method on the list because at any given time an element can be added or removed to the list with the class unsaved.
In fact when the page loads there will never be an element with class unsaved on the list. But during the course of time an element with that class can be added and if so I don't want the user to be able to sort and as soon as it is removed I want to re-enable sorting.
Hope that clarifies my issue.