Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 073cbcf

Browse files
authored
docs(README): improve cross-list canceling notes
1 parent 723a2a5 commit 073cbcf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,19 @@ $scope.sortableOptions = {
142142
**Notes:**
143143
* `update` is the appropriate place to cancel a sorting, since it occurs before any model/scope changes but after the DOM position has been updated.
144144
So `ui.item.scope` and the directive's `ng-model`, are equal to the scope before the drag start.
145-
* To [cancel a sorting between connected lists](https://github.com/angular-ui/ui-sortable/issues/107#issuecomment-33633638), `cancel` should be called inside the `update` callback of the originating list.
145+
* To [cancel a sorting between connected lists](https://github.com/angular-ui/ui-sortable/issues/107#issuecomment-33633638), `cancel` should be called inside the `update` callback of the originating list. A simple way to is to use the `ui.item.sortable.received` property:
146+
```js
147+
update: function(event, ui) {
148+
if (// ensure we are in the first update() callback
149+
!ui.item.sortable.received &&
150+
// check that its an actual moving between the two lists
151+
ui.item.sortable.source[0] !== ui.item.sortable.droptarget[0] &&
152+
// check the size limitation
153+
ui.item.sortable.model == "can't be moved between lists") {
154+
ui.item.sortable.cancel();
155+
}
156+
}
157+
```
146158

147159
### jQueryUI Sortable Event order
148160

0 commit comments

Comments
 (0)