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

Prevent dropping if level already has X amount of nodes. #65

Open
NeoMarine opened this issue Mar 26, 2019 · 3 comments
Open

Prevent dropping if level already has X amount of nodes. #65

NeoMarine opened this issue Mar 26, 2019 · 3 comments

Comments

@NeoMarine
Copy link

I want to prevent "moving" (dragging/dropping) a node to a level that already has a specific number of nodes on that level.

For example, at level 0 (top level) I want to restrict it to just 1 node on that level, and for any other levels (children levels) I want to allow them up to 10 nodes on those levels.

Any idea how this could be accomplished?

I thought that with ondragend() function I could "return false;" after getting the "target node level" and then getting the number of nodes on that target node level, but unfortunately ondragend() does not provide any means to know what level you are moving (dragging/dropping) the node to.

For example:

ondragend(node, draggableHelperInfo){

var maxNodesOnFirstLevel = 1;
var maxNodesOnOtherLevels = 10;

// node.afterDropLevel does not exist, but I wish it did!
// nodesOnDropLevel = add code here to find out how many nodes already exist on the target drop level

if (node.afterDropLevel ==0 && nodesOnDropLevel >= maxNodesOnFirstLevel){

return false;

} else if (nodesOnDropLevel >= maxNodesOnOtherLevels){

return false;

}
@phphe
Copy link
Owner

phphe commented Apr 1, 2019

sorry for the late reply.
check the source about drop event at https://github.com/phphe/vue-draggable-nested-tree/blob/master/src/components/DraggableTreeNode.vue#L61
the moving target is the drag placeholder on drag end. so
target level: store.dplh._vm.level

@NeoMarine
Copy link
Author

NeoMarine commented Apr 2, 2019

Thank you!

I managed to get it working by finding the target level and also finding the number of nodes on that level at the same time with dplh (drag placeholder):

var targetLevel = this.$refs.tree.dplh._vm.level;
var nodesAtTargetParentCount = this.$refs.tree.dplh.parent.children.length;

@felixpenrose
Copy link

felixpenrose commented May 20, 2019

Thank you!

I managed to get it working by finding the target level and also finding the number of nodes on that level at the same time with dplh (drag placeholder):

var targetLevel = this.$refs.tree.dplh._vm.level;
var nodesAtTargetParentCount = this.$refs.tree.dplh.parent.children.length;

@NeoMarine I'm trying to do something very similar, could you share your code in context of the ondragend function.

I've tried to write the following

dragend(node, draggableHelperInfo) {

        console.log(this.$refs.tree.dplh._vm.level;);
},

However tree and dplh are both undefined.

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

No branches or pull requests

3 participants