gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

grid doesnt deactivate droppable properly when using acceptWidgets

Open nelsonad opened this issue 10 years ago • 18 comments

I have an issue when adding multiple external items via drag and drop. The first draggable item works well, the grid activates and shows the placeholder and moves existing nodes out of the way.

The problem is with subsequent items, the grid doesn't activate immediately like the first item. It will start working if the new dragged item is moved out and triggers the draggable dropout event.

I tracked it down to an issue with gridstack preventing droppable from calling deactivate after the item is dropped.

And I fixed it by changing gridstacks droppable accept function to check node._temporary

Before:

this.dd
  .droppable(self.container, {
     accept: function(el) {
          el = $(el);
          var node = el.data('_gridstack_node');
          if (node && node._grid === self) {
               return false;
          }
          return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
   }
})

After:

this.dd
      .droppable(self.container, {
            accept: function(el) {
                 el = $(el);
                 var node = el.data('_gridstack_node');
                 if (node && !node._temporary && node._grid === self) {
                      return false;
                 }
                 return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets);
             }
      })

nelsonad avatar Oct 19 '16 17:10 nelsonad

Faced the same issue. However, fix mentioned by you is no longer working.

When I try and drag it outside the bounds of the grid, dropout gets triggered and I can drag/drop in the grid again nicely.

Without that, I get stuck and error is thrown.

mandys avatar May 17 '17 08:05 mandys

@nelsonad - forgot to tag you.

mandys avatar May 17 '17 08:05 mandys

Looks like I'm experiencing the same thing - dragging a widget off a flyout menu into the gridstack, works the first time but not the second time. Unless you drag the widget right to the top of the screen, in this case it's under the top menu. Will this one get fixed?

petegibbins avatar Sep 01 '17 12:09 petegibbins

@petegibbins did you try making the change i posted above? It's still working for me

nelsonad avatar Sep 01 '17 15:09 nelsonad

@nelsonad Hi - yep tried that but no luck for me. I'm using v1 of the framework, could you be using an older version where this works? See that @mandys says it's "no longer" working.

petegibbins avatar Sep 01 '17 15:09 petegibbins

@petegibbins oh, ya maybe that's it, i'm using v0.3.0 =/

nelsonad avatar Sep 01 '17 15:09 nelsonad

@nelsonad Tried on v0.3.0 still no dice unfortunately. The 'dropover' event does not get fired 2nd time around.

This line always returns undefined on the 2nd drag / drop. var node = el.data('_gridstack_node');

petegibbins avatar Sep 01 '17 16:09 petegibbins

I have the same issue, do we know in which revision the workaround stopped working?

AaronRobson avatar Sep 01 '17 17:09 AaronRobson

Same issue...

lauantai avatar Apr 04 '18 15:04 lauantai

I thought this had been fixed in a merged PR on v1. @petegibbins you're using the newest version in the develop branch and still having this problem?

radiolips avatar Apr 06 '18 13:04 radiolips

Same Issue.

Please fix this issue. Thanks

@radiolips

benjamincfaustino avatar Apr 17 '18 05:04 benjamincfaustino

Same issue please fix thanks!

polenginlabu avatar Apr 17 '18 05:04 polenginlabu

This is working for me on v0.4.0, released yesterday. I'm seeing it work fine on the demo - http://gridstackjs.com/demo/two.html - I'm closing the ticket, but if someone has a specific problem, please let me know.

radiolips avatar May 12 '18 14:05 radiolips

I'm still experiencing this one see #940 every after dragstop and try adding a new widget on a flyout menu it triggers and error " Uncaught TypeError: Cannot set property '_grid of undefined" line 933 "node._grid = self; "

jun1432 avatar Sep 18 '18 05:09 jun1432

This is working for me on v0.4.0, released yesterday. I'm seeing it work fine on the demo - http://gridstackjs.com/demo/two.html - I'm closing the ticket, but if someone has a specific problem, please let me know.

I am still experiencing this issue in v0.4.0

mishrarajesh avatar Dec 05 '18 12:12 mishrarajesh

@mishrarajesh @jun1432 @polenginlabu @benjamincfaustino The fix for me was: https://github.com/jquery/jquery-ui/pull/1181/commits/2228050b2c3312267ade756168419b972721f157

stefan2595 avatar Apr 11 '19 10:04 stefan2595

I am still facing this issue added below code : this.dd .droppable(self.container, { accept: function(el) { el = $(el); var node = el.data('_gridstack_node'); if (node && !node._temporary && node._grid === self) { return false; } return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets); } })

Still not working for me . Please suggets me what to do now

LaxmanTelang avatar Feb 14 '20 13:02 LaxmanTelang

@LaxmanTelang can you provide a jsfidle sample showing the issue with latest code ? use https://jsfiddle.net/adumesny/jqhkry7g as starting point.

adumesny avatar Feb 14 '20 20:02 adumesny