I have two lists #sortable1
and #sortable 2
which are connected sortables, as shown in this example.
You can drag and drop list items from sortable1
to sortable 2
. However, if an item in sortable 1 contains the class "number", I want to prevent the drop on Sortable2 and thus make the dragged item drop back into sortable 1.
I have used the following on sortable2:
receive: function (event, ui) {
if ($(ui.item).hasClass("number")) {
$(ui.item).remove();
}
but it deletes the list item from both tables altogether. Any help will be appreciated.
Best Answer
For anyone reading this in future, as mentioned by briansol in comments for the accepted answer, it throws error
The the documentation particularly says
Canceling the sort during other events is unreliable, So it's better use the
receive
event as shown in Mj Azani's answer or use thestop
event as follows:Demo