[Proposal] Allow Cancel Later Than First Update() #254
Description
When using ui-sortable with connected lists, a drag can only be cancelled in the first call to update()
. However, the first time update()
is called one often does not have enough information to make a decision on whether to cancel. Let me give an example.
Say I have two connected lists, where some entries may be in both lists, but where neither list can contain the same entry twice:
List 1 | List 2 |
---|---|
Chicago | Los Angeles |
Seattle | Dallas |
Seattle | |
Miami |
If I drag "Seattle" from one list to the other, I want ui-sortable
to cancel in order to prevent a duplicate. But in the first call to update()
, ui.item.sortable.moved
is not yet set (remove()
hasn't run), so I don't know that I'm dragging Seattle. I see three possible solutions:
- Let the developer figure out which model is being moved and what model it's being moved into based on the DOM elements/index. This is less than ideal, in that I don't like to have jQuery in my controllers. OR...
- Change
stop()
inui-sortable
so that it detects a cancelled move and undoes the splice thatremove()
did, i.e., restore the models to their original condition. This would allow a cancel in the secondupdate()
or even inreceive()
. OR... - Set additional properties on
ui.item.sortable
duringstart()
, so that the developer has more information in the first run ofupdate()
, without having to query the DOM. Additional info could include the model of the sending list and model of the moved item. In the first internalupdate()
callback, the model of the target list could also be set, if applicable. That would provide everything needed to detect a potential duplicate in the target list.
Obviously I would favor 2 or 3, or maybe even 2 and 3 both.
ORIGINAL TITLE: [Proposal] Allow Cancel Later Than First Update() OR Provide More Options