Search code examples
javascriptpolymerpolymer-1.0rubaxa-sortable

RubaXa/Sortable cancel item drop using Polymer


I'm using Rubaxas sortable.js which is amazing.

Now i try to cancel a drop and it won't work.

The docs says :

onMove: function (/**Event*/evt) {
    // Example: http://jsbin.com/tuyafe/1/edit?js,output
    evt.dragged; // dragged HTMLElement
    evt.draggedRect; // TextRectangle {left, top, right и bottom}
    evt.related; // HTMLElement on which have guided
    evt.relatedRect; // TextRectangle
    // return false; — for cancel
}

So I tryed this like in this example:

Code :

<sortable-js id="sortable" animation="1000" filter=".noDrag" on-move="_elementMoving" on-end="_elementMoved" force-fallback="true", fallback-class="fallback">
  <template is="dom-repeat" items="{{items.images}}">
    <admin-image index$="{{index}}" type="{{type}}"  image-set="{{_hasImage(item)}}" class$="admin_image {{_isDraggable(item, items, item.cover)}}" item="{{item}}"></admin-image>  
  </template>
</sortable-js>

_elementMoving() function :

_elementMoving : function(e){
    return e.related.className.indexOf('noDrag') === -1;
  }
},

So what am I doing wrong here?

@RubaXa

Help would be greatly appreciated.


Solution

  • I solved my problem like this:

    Instead of using filter I used draggable.

    Code :

    <sortable-js id="sortable" animation="1000" draggable=".drag" on-move="_elementMoving" on-end="_elementMoved" force-fallback="true", fallback-class="fallback">
      <template is="dom-repeat" items="{{items.images}}">
        <admin-image  index$="{{index}}" type="{{type}}"  image-set="{{_hasImage(item)}}" class$="admin_image {{_isDraggable(item, items, item.cover)}}" item="{{item}}"></admin-image>  
      </template>
    </sortable-js>
    

    _elementMovingfunction stays the same.