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

maximum attachment #12

Closed
LusenkoSasha opened this issue Jul 20, 2018 · 2 comments
Closed

maximum attachment #12

LusenkoSasha opened this issue Jul 20, 2018 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@LusenkoSasha
Copy link

how to set the maximum attachment for each element?

@holiber holiber self-assigned this Jul 20, 2018
@holiber holiber added the question Further information is requested label Jul 20, 2018
@holiber
Copy link
Owner

holiber commented Jul 23, 2018

Hi. You can restore previous value in the @input handler if the new one is not something that you expected.

      <sl-vue-tree
          v-model="nodes"
          ref="slVueTree"
          @input="onInputHandler"
      />
new Vue({
    el: '#app',
    components: { SlVueTree },
    data: function () {
     return {
       nodes: nodes,
       prevNodes:  this.cloneDeep(nodes)
     }
    },
 methods: {


      onInputHandler(newNodes) {
        let slVueTree = this.$refs.slVueTree;
        let limitReached = false;
        let childrenLimit = 3;

        slVueTree.traverse((node) => {
          if (node.children.length > childrenLimit) limitReached = true;
        });

        if (limitReached) {
          alert('Limit is reached');
          this.nodes = this.cloneDeep(this.prevNodes);
          return;
        }

        this.prevNodes = this.cloneDeep(newNodes);
      },

      cloneDeep(obj) {
        return JSON.parse(JSON.stringify(obj))
      }
 }
})

@rmirabelle
Copy link

Regarding the example above, it's important to add the once modifier to the @input attribute, otherwise, onInputHandler will likely be called TWICE for every node drop. It seems that at least one of the following event listeners also triggers an input event:

<sl-vue-tree
        v-model="nodes"
        ref="slVueTree"
        @select="onSelectHandler"
	@drop="onDropHandler"
	@toggle="onToggleHandler"
	@nodecontextmenu="onNodecontextmenuHandler"
	@input.once="onInputHandler"
      />

Obviously, it would be great to have full-bodied support for both node drag and node drop validation. New API methods for allowDrag and allowDrop, when returning false, should do all the work of preventing a node drag or drop, including displaying a not-allowed mouse cursor.

I'm going to wind up having to roll my own solution for this. Once I get it up and running, I'll share.

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

No branches or pull requests

3 participants