question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event on nested draggables

See original GitHub issue

Dear all,

It has been many hours that I’m working on it and I’m stucked on something so I contact you. I saw many topics on nested draggable but there isn’t my answer.

Context:

  • I have two nested draggables
  • I use vuex to manage the data (and the get and set in computed)

I try to set an event on items order change (parent or children) to start my ajax request and save the data, however, as there are two nested draggables, whatever I use, @end, @sort, @change, @update or even watch… sometimes it fires two times (or I don’t want to start my ajax request two times). Please check my screen record https://youtu.be/GJbCeka8xI4, at the end in the console you’ll see it fires two times (for this example I use the change, on both draggables).

Is there a way, from the parent draggable, to detect any change (even from the children draggable it self) and fire a unique function?

My code:

<draggable v-model="publicPages" :options="{animation: 150, group: group}" @start="drag=true" @end="drag=false;" @update="onReorderEnd();" class="pages-container" v-bind:class="{ 'no-spacer' : !spacers }">
            <div class="page-container" v-for="(publicPage, index) in publicPages" v-bind:class="{ last : index === publicPages.length - 1 }">
                  <page v-bind:page="publicPage" v-bind:pageIndex="index" v-bind:group="group"></page>
                  <div v-if="publicPage.type === 'password'" class="protected-pages-container">
                    <div class="protected-notice">
                        <span class="protected-notice-icon icon-lock"></span>
                        <span class="protected-notice-content">Protected pages</span>
                    </div>
                    <sub-draggable v-if="publicPage.children" :page="publicPage" :pages="publicPage.children" :group="group" :spacers="spacers"></sub-draggable>
                  </div>
                  <span v-if="spacers" class="page-spacer icon-chevron-thin-right"></span>
              </div>
</draggable>

computed: {
      publicPages: {
        get() {
          return this.$store.state.campaignsPages.pages[this.group];
        },
        set(value) {
          this.$store.commit('campaignsPages/updateCampaignPagesState', {group:this.group, data:value});
        }
      }
    }

>>>> sub-draggable code below

<template>
  <draggable v-model="protectedPages" :options="{animation: 150, group: group}" @start="drag=true" @end="drag=false;" @update="onReorderEnd();" class="protected-pages">
    <div v-for="(protectedPage, protectedIndex) in protectedPages" class="page-container" v-bind:class="{ last : protectedIndex === protectedPages.length - 1 }">
        <page v-bind:page="protectedPage" v-bind:pageIndex="protectedIndex" group="protectedPages"></page>
        <span v-if="spacers" class="page-spacer icon-chevron-thin-right"></span>
    </div>
  </draggable>
</template>

computed: {
      protectedPages: {
        get() {
          return this.pages;
        },
        set(value) {
          this.$store.commit('campaignsPages/updateCampaignPasswordPagesState', {page: this.page, data:value});
        }
      }
    }

mixin

onReorderEnd() {
     this.$store.commit('campaignsPages/loopCampaignPages');
},

Thank you in advance for your help!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
clecocqcommented, Oct 21, 2017

Dear David,

Thank you for your answer and time, I got it working with your solution but with @change (not @end, because in one case it doesn’t fire, children to parent). So all is ok for me now, thank you again.

Cyril

0reactions
TLA020commented, Nov 14, 2019

I fixed this issue by deep comparing the oldVal and newVal.

If any changes… then fire event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make a Draggable Div on React with nested event?
I want to make a draggable modal from scratch. ... the element that using onDrag event inside onMouseDown will only trigger onMouseDown ....
Read more >
Disable drag container when interacting with nested draggables
Is it possible to ignore all events on a drag container ( type = scroll ) when I drag a nested element (...
Read more >
4333 (Nested draggables problem in IE) - jQuery UI
Whenever the outher div is draggable but the inner div is not, the event will not be bubbled to the outer div and...
Read more >
Nested Drag And Drop - StackBlitz
<div *ngFor="let app of apps">. <div draggable="true" (dragstart)="drag. ($event, app.id)">. <span>{{ app.name }}</span>.
Read more >
Lean & Mean Drag and Drop - LMDD
Drag and Drop script for complex nested html structures. ... Supports nested structures ('nestable sortables'). Smooth transitions ... Supports touch events.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found