Skip to main content

Search and Top Navigation

#15273 new bug ()

Opened February 20, 2018 10:16PM UTC

Last modified February 20, 2018 10:19PM UTC

Using a draggable with a connected sortable causes error if sort returns false

Reported by: pvbergen Owned by:
Priority: minor Milestone: none
Component: ui.draggable Version: 1.12.1
Keywords: Cc:
Blocked by: Blocking:
Description

Using a draggable with a connected sortable causes an "Uncaught TypeError: Cannot read property '0' of null" when sortable.sort returns false.

I guess that the sortable destroys the dragged element and draggable wants to access it afterwards.

Example

$(".sortable").sortable({
  sort: function(e, t) {
    return false;
  }
});
$(".draggable").draggable({
  connectToSortable: ".sortable",
});

Codepen

https://codepen.io/anon/pen/XZELqm

Current workaround

  • Return true in sort and handle cancellation in stop callback.
  • Use $(t.item).trigger('mouseup'); in draggable.drag to stop drag.

Background

I want to implement cancelling of a drag operation into a sortable. Sort returning false cancels the operation on mousemove instead of waiting for mouseup and stop.

Attachments (0)
Change History (1)

Changed February 20, 2018 10:19PM UTC by pvbergen comment:1

description: Using a draggable with a connected sortable causes an "Uncaught TypeError: Cannot read property '0' of null" when sortable.sort returns false. \ I guess that the sortable destroys the dragged element and draggable wants to access it afterwards. \ \ == Example \ {{{ \ $(".sortable").sortable({ \ sort: function(e, t) { \ return false; \ } \ }); \ $(".draggable").draggable({ \ connectToSortable: ".sortable", \ }); \ }}} \ \ == Codepen \ https://codepen.io/anon/pen/XZELqm \ \ == Current workaround \ Return true in sort and handle cancellation in stop callback. \ \ == Background \ I want to implement cancelling of a drag operation into a sortable. Sort returning false cancels the operation on mousemove instead of waiting for mouseup and stop. \ Using a draggable with a connected sortable causes an "Uncaught TypeError: Cannot read property '0' of null" when sortable.sort returns false. \ I guess that the sortable destroys the dragged element and draggable wants to access it afterwards. \ \ == Example \ {{{ \ $(".sortable").sortable({ \ sort: function(e, t) { \ return false; \ } \ }); \ $(".draggable").draggable({ \ connectToSortable: ".sortable", \ }); \ }}} \ \ == Codepen \ https://codepen.io/anon/pen/XZELqm \ \ == Current workaround \ - Return true in sort and handle cancellation in stop callback. \ - Use $(t.item).trigger('mouseup'); in draggable.drag to stop drag. \ \ == Background \ I want to implement cancelling of a drag operation into a sortable. Sort returning false cancels the operation on mousemove instead of waiting for mouseup and stop. \

Completed workaround