thgreasi / ui-sortable-multiselection

Provide multiple element sorting in UI-Sortable
MIT License
30 stars 12 forks source link

Items are inserted incorrectly if dropzone contains html other than sortable items #10

Closed jessefoster closed 9 years ago

jessefoster commented 9 years ago

I have placeholder text in one of my dropzones. After multiple items are dropped the index is incorrectly calculated as it considers the placeholder text as part of the sortable list. Here's a live example, http://codepen.io/anon/pen/jbLYqa. Whatever item you use to drag the list is inserted first.

The origin of this bug is in ui-sortable as it provides the index you're using from ui.item.sortable.dropindex.

scope.$apply(function () {
  var ngModel = ui.item.sortable.droptargetModel,
        newPosition = ui.item.sortable.dropindex,
        models = ui.item.sortableMultiSelect.moved;

I tried working around this issue within ui-sortable-multiselection but couldn't find a clean way since ui-sortable modifies the DOM before your methods are called.

I did put together a possible fix in my fork of ui-sortable, jessefoster/ui-sortable@7a394a6d4bdb728b86d7f1a6ed693910cf2ec216

thgreasi commented 9 years ago

UI-Sortable's README clearly states that:

ui-sortable element should only contain one ng-repeat and not any other elements (above or below). Otherwise the index matching of the generated DOM elements and the ng-model's items will break. In other words: The items of ng-model must match the indexes of the generated DOM elements.

thgreasi commented 9 years ago

This is already solved in UI-Sortable v0.14.x-dev branch, but not in any implementation of ui-sortable-multiselection. Thanks for your effort.