Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe2e173

Browse files
committed
fix to drag between 2 grids and back
* fix for gridstack#1484, introduced in 2.0.1 * make sure we reset _added flag when leaving other grid and we get back
1 parent 4933987 commit fe2e173

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Change log
4545

4646
- we now have a React example, in addition to Vue - Angular is next!. thanks [@eloparco](https://github.com/eloparco)
4747
- fix placeholder not having custom `GridStackOptions.itemClass`. thanks [@pablosichert](https://github.com/pablosichert)
48+
- fix [1484](https://github.com/gridstack/gridstack.js/issues/1484) draging between 2 grids and back (regression in 2.0.1)
4849
- del `ddPlugin` grid option as we only have one drag&drop plugin at runtime, which is defined by the include you use (HTML5 vs jquery vs none)
4950

5051
## 2.2.0 (2020-11-7)

src/gridstack-dd.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
120120
}
121121
})
122122
.on(this.el, 'dropover', (event, el: GridItemHTMLElement) => {
123-
// ignore dropping on ourself, and prevent parent from receiving event
123+
// ignore drop enter on ourself, and prevent parent from receiving event
124124
let node = el.gridstackNode || {};
125-
if (node.grid === this) { return false; }
125+
if (node.grid === this) {
126+
delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
127+
return false;
128+
}
126129

127130
// see if we already have a node with widget/height and check for attributes
128131
if (el.getAttribute && (!node.width || !node.height)) {
@@ -151,12 +154,18 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
151154
return false; // prevent parent from receiving msg (which may be grid as well)
152155
})
153156
.on(this.el, 'dropout', (event, el: GridItemHTMLElement) => {
157+
let node = el.gridstackNode;
158+
if (!node) { return; }
159+
160+
// clear any added flag now that we are leaving #1484
161+
delete node._added;
162+
154163
// jquery-ui bug. Must verify widget is being dropped out
155164
// check node variable that gets set when widget is out of grid
156-
let node = el.gridstackNode;
157-
if (!node || !node._isOutOfGrid) {
165+
if (!node._isOutOfGrid) {
158166
return;
159167
}
168+
160169
GridStackDD.get().off(el, 'drag');
161170
node.el = null;
162171
this.engine.removeNode(node);

0 commit comments

Comments
 (0)