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
Can't set an id to a widget through setupDragIn #2231
Comments
actually I spent an hour yesterday on this... and got it working in few minutes this morning after a good night sleep GridStack.setupDragIn('.gridstack-add-widget', {
appendTo: '.gridstack-widget-dragged',
helper: function (event: Partial<DragEvent>) {
const id = nanoid();
const target = event.target as GridItemHTMLElement;
const correctTarget = target.parentElement!.classList.contains('grid-stack-item-content') ? target.parentElement!.parentElement! : target.parentElement!;
correctTarget.setAttribute('gs-id', id);
const clone = Utils.cloneNode(correctTarget);
return clone;
},
}); |
would you know why the code above works but this one does not GridStack.setupDragIn('.gridstack-add-widget', {
appendTo: '.gridstack-widget-dragged',
helper: function (event: Partial<DragEvent>) {
const id = nanoid();
const target = event.target as GridItemHTMLElement;
const correctTarget = target.parentElement!.classList.contains('grid-stack-item-content') ? target.parentElement!.parentElement! : target.parentElement!;
const clone = Utils.cloneNode(correctTarget);
clone.setAttribute('gs-id', id); // set attribute on cloned element
return clone;
},
}); when I set the attribute gs-id after creating the clone (which seems cleaner isn't it? The id does not get added |
actually if you care about id (as you should) set the initial gs-id (or id optoin when creating from json) and NOT when the drag happen. the node gs-is is ONLY the dom used for layout. the internal node.id is what is used during actual code collision... and next time please post a slack question - this isn't a lib bug per say, so others can search/respond. |
I didn't understand :/ Let me give more details on the use case:
my current implementation:
Setting the id and removing the className from the cloned element does not work for me, that's why I clone the element after. It works Two issues I have to calm my inner asperger alterego with:
@adumesny I tried to connect to slack. But I couldn't, I'm getting the same issue as #2230 Update: I was able to join the slack channel. I opened #2233 |
don't have time to read this now... re-opening so I can check later. Update: demo/two.html now shows issue. |
help debug gridstack#2231 * will need to figure out why clone element is not used directly on drop later.
ok, I've taken the time to take a look... the clone should be used for creating the constrain (agree it's cleaner to set on clone rather than original master item) and it should also insert that content as is (with some check for required .grid-stack-item + .grid-stack-item-content) won't be small change and might break some user who were working around the issue... related to #1840 |
we fix a lot of bugs https://gridstackjs.com/demo/two.html affected by https://github.com/gridstack/gridstack.js#migrating-to-v8 removed GridStackOptions.dragInOptions since GridStack.setupDragIn() has it replaced since 4.0 gridstack/gridstack.js#2231
Subject of the issue
I rely deeply on grid stack IDs (gs-id), I need a way to track the widgets
Your environment
Steps to reproduce
Here is my helper function:
Expected behavior
I expect to set an id with
GridStack.setupDragIn
functionThe text was updated successfully, but these errors were encountered: