Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable dragging on specific element using Vue.Draggable

How can I set so that only .btn-drag can drag whole row? I am using https://github.com/SortableJS/Vue.Draggable

Currently I can drag also with button#options which is undesired

    <draggable v-model="textElements">
        <transition-group>
            <div class="is-draggable" v-for="element in textElements" :key="element.text">
                <div>
                    {{ element.text }}
                </div>
                <button class="btn btn-transparent">Options</button>
                <button class="btn btn-transparent btn-drag">Drag</button>
            </div>
        </transition-group>
    </draggable>

In docs they mention that we can place :move="checkMove" on <draggable> but in function I am not sure how can I check what exactly was dragged? Returning false works correctly for disabling dragging in general

methods: {
    checkMove(evt) {
        console.log(evt)
        return false
    }
}

Console.log(evt) shows this but I am not sure which property I can use to pinpoint exactly what started a drag https://image.prntscr.com/image/r17zNkxoSWGdVQs_5nR09w.png

like image 971
Marko Avatar asked Dec 26 '17 20:12

Marko


3 Answers

Starting from version 2.19, you can use

<draggable handle=".handle">
like image 61
David Desmaisons Avatar answered Oct 31 '22 17:10

David Desmaisons


The functionality is called "handles".

https://github.com/SortableJS/Vue.Draggable#features

https://github.com/SortableJS/Vue.Draggable#options

https://github.com/RubaXa/Sortable#options
handle option here should help.

like image 16
Bsalex Avatar answered Oct 31 '22 18:10

Bsalex


Here the elements with class "item" are only draggable , that can specified like this draggable=".item" usign the draggable option inside the draggable tag

<draggable v-model="myArray" draggable=".item">
<div v-for="element in myArray" :key="element.id" class="item">
    {{element.name}}
</div>
<button slot="header" @click="addPeople">Add</button>
like image 4
Prashanth Bhonagiri Avatar answered Oct 31 '22 17:10

Prashanth Bhonagiri