• DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        Simple Vue.Draggable inside nested ul list breaks during render

        1.1k Views Asked by Alex Beschler At 15 January 2021 at 05:54 2025-12-10T08:19:08.541000

        Edit

        I tried creating a simple sandbox based on @Amaarrockz's feedback and the issue I'm having still seems to crop up:

        <div id="app">
            <ul>
                <li v-for="stepTitle in collections.stepTitles">
                    {{ stepTitle.name }}
                        <draggable tag="ol" v-model="collections.children">
                            <li v-for="child in collections.children">{{ child.step }}</li>
                        </draggable>
                </li>
            </ul>
        </div>
        
        Vue.use('draggable');
        var collection = {
            "stepTitles": [{
                "name": "Step 1",
                "id": 1
            }, {
                "name": "Step 2",
                "id": 2
            }, {
                "name": "Step 3",
                "id": 3
            }],
            "children": [{
                    "parentID": 1,
                    "step": "Child 1"
                },
                {
                    "parentID": 2,
                    "step": "Child 1"
                },
                {
                    "parentID": 2,
                    "step": "Child 2"
                },
                {
                    "parentID": 2,
                    "step": "Child 3"
                },
                {
                    "parentID": 3,
                    "step": "Child 1"
                },
                {
                    "parentID": 3,
                    "step": "Child 2"
                }
            ]
        };
        new Vue({
            el: '#app',
            data: {
                collections: collection
            }
        });
        

        The ultimate result I'd like should be:

        • Step 1 (Not draggable)
          1. Child 1 (Draggable)
        • Step 2 (Not draggable)
          1. Child 1 (Draggable)
          2. Child 2 (Draggable)
          3. Child 3 (Draggable)
        • Step 3 (Not draggable)
          1. Child 1 (Draggable)
          2. Child 2 (Draggable)

        where children should only extend to 1 level and be movable within their respective parents.

        I've whittled it down to the fact that there seems to be an issue rendering a <draggable> inside a parent <ul>. If I make a 2 dimensional JSON array that uses the parent's v-for variable, like stepTitle, it comes with an error about stepTitle is not defined. If I make a 1 dimensional JSON array and use different v-for variables, it doesn't render the HTML correctly.

        I've searched everywhere for examples with nested draggables but all the examples I find show the parent being draggable which isn't the result I'd like. In addition, the child was able to become a parent which is also not what I want.

        The incorrect rendering tells me I've done something wrong, but does vue-draggable have issues with rendering children <draggable> inside a regular <ul>?

        Original Post

        I have an interesting problem when using vue.draggable that I've spent hours trying to figure out.

        The general concept is that I have an array that contains a nested array. Here's the data:

        "steps": [{
            "name": "Title 1",
            "steps": ["Sub step 1"]
        }, {
            "name": "Title 2",
            "steps": ["Sub step 1", "Sub step 2", "Sub step 3"]
        }, {
            "name": "Title 3",
            "steps": ["Sub step 1", "Sub step 2"]
        }]
        

        which should render something like this: Proper render

        The goal is to get those sub steps draggable and have the Vue array adjust accordingly. However when I introduced the <draggable> tag the code breaks with a:

        Property or method "item" is not defined on the instance but referenced during render.

        Here's the full code for context:

        HTML

        <ul class="steps-section-added">
            <li class="list-group" v-for="(item, index) in stepSections" :key="item.stepSectionTitle" v-on:remove="removeAddedStepSection(index)">
                <div class="row">
                    <div class="col-12">
                        <div class="ist-group-item list-group-item-steps-header" style="display: table;width: 100%;">{{ item.stepSectionName }}
                            <span>
                                <button class="btn btn-outline-success-white float-right d-flex justify-content-center align-content-between ml-2" v-on:click="removeAddedStepSection(index)"><span class="material-icons">delete</span></button>
                                <button class="btn btn-outline-success-white float-right d-flex justify-content-center align-content-between" v-on:click="editAddedStepSection(index)"><span class="material-icons">edit</span></button>
                            </span>
                        </div>
                        <div>
                            <!-- Code breaks somewhere here-->
                            <draggable v-model="item.steps" tag="ol" @start="drag=true" @end="drag=false" style="padding-left: 0px;">
                                <li class="recipe-list-group-item list-group-item list-group-item-steps-body" v-for="t in item.steps">{{ t.stepText }}</li>
                            </draggable>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
        

        Vue app

        Vue.use('draggable');
        var stepsVM = new Vue({
            el: '#step-section-ingredients',
            data: {
                steps: [],
                stepSections: [],
                stepSectionTitle: '',
                drag: false
            },
            methods: {
                addNewStep: function () {
                    //
                },
                removeTextRow: function (index) {
                    //
                },
                addNewStepSection: function () {
                    //
                },
                removeAddedStepSection: function (index) {
                    //
                },
                editAddedStepSection: function (index) {
                    //
                }
            }
        });
        

        If I replace the <draggable> tag to an <ol> it renders correctly but the nested components aren't draggable. As soon as I introduce the draggable tag it breaks. From hours of experimenting I think the error is referring to the v-for="t in item.steps">. If this is the case, how do I get the item.steps to work?

        Any guidance would be appreciated :)

        javascript html vue.js vue.draggable
        Original Q&A
        1

        There are 1 best solutions below

        0
        Amaarockz Amaarockz On 15 January 2021 at 17:07

        Yes your structure should be something like this

        "steps": [{
            "name": "Step 1",
             id: 1,
             parentId: null
        }, {
            "name": "Sub Step 1",
             id: 11,
             parentId: 1
        }, {
            "name": "Sub Step 2",
             id: 12,
             parentId: 1
        }, {
            "name": "Step 2",
             id: 2,
             parentId: null
        }]
        

        This is a one-dimension array but can extend upto n-levels. If you could maintain a structure like this then using vue-draggable you 'sub-step' from Step1 to Step2, based on the shift you just need to update your parentId's

        Related Questions in JAVASCRIPT

        • Using Puppeteer to scrape a public API only when the data changes
        • inline SVG text (js)
        • An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
        • Storing the preferred font-size in localStorage
        • Simple movie API request not showing up in the console log
        • Authenticate Flask rest API
        • Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
        • How to request administrator rights?
        • mp4 embedded videos within github pages website not loading
        • Scrimba tutorial was working, suddenly stopped even trying the default
        • In Datatables, start value resets to 0, when column sorting
        • How do I link two models in mongoose?
        • parameter values only being sent to certain columns in google sheet?
        • Run main several times of wasm in browser
        • Variable inside a Variable, not updating

        Related Questions in HTML

        • How to store a date/time in sqlite (or something similar to a date)
        • How to use custom font during html to pdf conversion?
        • Storing the preferred font-size in localStorage
        • mp4 embedded videos within github pages website not loading
        • Scrimba tutorial was working, suddenly stopped even trying the default
        • Is there any way to glow this bulb image like a real light bulb
        • With non-graphical maps in Leaflet, zoomDelta doesn't work
        • What can I do to improve my coding on both html and css
        • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
        • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
        • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
        • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
        • Storing selected language in localStorage
        • Fences (parenthesis, braces) in HTML and MathML
        • Understanding Scroll Anchoring Behavoir

        Related Questions in VUE.JS

        • Problems with matter.js and i18n in vue.js
        • Form Validation not working in custom component Vue
        • Authenticating vue app on each route change
        • Vue/TailwindCSS - Content is behind Sidebar
        • Vue3 Suspense Parent > Child Animation
        • Pass dynamic object data via nuxt-link to component
        • Failed to resolve import, but the path is valid, and detected as such by VSCode
        • how to use less variables in vue components?
        • Prevent a webpage from navigating away
        • Creating a modal window in product edit page in Shopware6 and saving data to custom table(repository) from a form within the modal window
        • How do I fix (or ignore) a TypeScript error that's inside a HTML template?
        • Vue.js Checkbox Alignment Issue: Centering Checkboxes Within Table Cells
        • How to reset vue product filter?
        • Vue display output of two dimensional array
        • vue js error when adding bonus items to another item

        Related Questions in VUE.DRAGGABLE

        • How can I get relatedContext.element in Vue draggable in nested elements?
        • How can I store the expandable position in vue application
        • how can to revert draggable's initial state
        • Disallowing the movement of one element from an area to an another one using Vue.Draggable
        • Draggable large list performance - Vue js
        • What property is linking these two lists in vue.draggable?
        • How do I customize the "ghost" element with Vue.Draggable
        • Vue Draggable, mark elements as undraggable?
        • <draggable> with dynamic groups
        • Why will vue draggable items not move between lists?
        • How can I save order of v-cards when using vue draggable?
        • Vue3 with Vue.draggable-next drag and drop problem
        • ChartJS charts width and height set to 0 when responsive and dragged. Any ideas as to why?
        • Sortable.js/Vue..Draggable@next initial order of elements is incorrect
        • Styling .sortable-drag element in Vue.Draggable and Sortablejs

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates