angular-ui / ui-sortable

jQuery UI Sortable for AngularJS
http://angular-ui.github.io/ui-sortable/
MIT License
1.26k stars 443 forks source link

How can I get the parent object of the array I am about to drop into? #512

Closed Lorless closed 7 years ago

Lorless commented 7 years ago

I have a use case where certain objects shouldn't be allowed inside certain containers. This is denoted by the 'selectorType' field on the object.

The problem is that the dropTargetModel is the actual array im dropping into and not the parent object so I can't check what the parent type is, only the siblings. Is there any way around this?

thgreasi commented 7 years ago

I guess that you have a nested tree structure. This isn't covered by this control's implementation and you have to handle it yourself.

Some ways to iplement this would be:

Lorless commented 7 years ago

Thanks. Thats helpful :)

Lorless commented 7 years ago

@thgreasi On a related note, this question required that the validation be performed before the drop takes place. Ideally on the 'over' callback but the dropTarget does not seem to be populated. Is that correct or have i messed up somewhere?

thgreasi commented 7 years ago

Yea, the dropTarget is populated after the drop. You can use the ui parameter of the over callback following the jQuery UI API for such a specific use case.