angular-ui/ui-sortable

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

Lorless opened this issue · 4 comments

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?

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:

  • You could modify your model to include a reference to their parent item
  • You could use CSS classes for such nesting checks
  • You could use parent()/closest() to climb up the tree and then use .scope() to retrieve the element's model
  • You could traverse your tree structure to locate the element that contains the dropTargetModel arrray

Thanks. Thats helpful :)

@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?

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.