Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enableMove() removes snapping on existing items #1658

Closed
NealonF opened this issue Mar 11, 2021 · 4 comments · Fixed by #1680
Closed

enableMove() removes snapping on existing items #1658

NealonF opened this issue Mar 11, 2021 · 4 comments · Fixed by #1680
Labels

Comments

@NealonF
Copy link

NealonF commented Mar 11, 2021

Subject of the issue

When you call enableMove on a drag-disabled grid with existing items, the existing items will have drag unlocked but will not snap into grid cells as normal. Instead they just stay exactly wherever you drag them to. However, if you add a new item to the grid while enableMove is used this way, then the new item will have normal snapping behavior. This is for the JQ version. On the h5 version, the existing items will stay undraggable instead of the floating behavior. The rest of the results seem to be the same as JQ. The difference between versions should probably be verified just to make sure what I found is true.

Your environment

  • JQ 3.2 and JQ 3.3 and h5 3.3
  • Version 88.0.4324.190 (Official Build) (64-bit) and firefox 86 (64 bit)

Steps to reproduce

https://jsfiddle.net/q904xvfu/12/

push add button to add widget.
try dragging and see that it's locked.
press toggle button (confirmed in console output)
(JQ) drag existing widget and see that it does not snap into a cell. (h5) drag existing widget and see that it is still locked
add another widget and drag that one to see that it DOES snap into cell.
can click toggle again to lock the grid, then again to see that the issue applies to all existing items.

Expected behavior

Items should be snapping into cells when dragged, when drag is enabled this way

Actual behavior

on JQ, items wont snap and will float instead. on h5 they stay undraggable.

@adumesny
Copy link
Member

adumesny commented Mar 21, 2021

hey I can't access your demo anymore (502 bad gateway) but realized we do have an example that works
https://gridstackjs.com/demo/static.html
https://github.com/gridstack/gridstack.js/blob/master/demo/static.html

so you must be doing something different...

@NealonF
Copy link
Author

NealonF commented Mar 21, 2021

That's strange, it still works for me, and I sent it to some other people to see if it works for them too and it does. Maybe if I link it again? Worth a shot!
https://jsfiddle.net/7s694twh/3/

Took a little video of what I'm talking about. For some reason the capture program I used has the mouse misaligned, but notice when I toggle the grid to allow dragging by the method I explained, the items in the grid no longer attach to cells, you can just drag them to any spot. However, if you add a new item WHILE the dragging is already enabled, they will snap to cells when you drag them. Then, that same item will stop snapping to cells if you toggle off dragging and toggle it back on. A little hard to explain, hopefully this makes some sense.
https://drive.google.com/file/d/1qwWewDb198IQTOGhFbV_c2R9uese4ryr/view

And if for some reason you still can't view the code, i'll paste it here.

edit: code doesnt post normally here. i'll attach it as a txt file instead.
code.txt

@adumesny
Copy link
Member

I can access the links again... looking...

adumesny added a commit to adumesny/gridstack.js that referenced this issue Mar 22, 2021
* fix gridstack#1658
* we now set the grid options BEFORE we update each item as that override
* enableMove() and enableResize() no longer take a second optional param as we must set grid options for things to work
(if you want to enable current items but not change the grid itself, there is already the `movable('.grid-stack-item')` method that doesn't change the grid (no need for 2 ways)
* did some more cleanup and added test case.
@adumesny adumesny mentioned this issue Mar 22, 2021
3 tasks
@adumesny
Copy link
Member

fix in 4.0.2 - took a little longer than I though... if you find lib useful, don't forget to donate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants