Problem:
I'm trying to recreate the Draggable + Sortable functionality from jQuery and can't get the dropped element to go into my array of objects.
I want to drag a $.draggable() button into a $.sortable() list.. I want the button to represent an object with properties (could be assoc array, or the object itself) and when I drop it in my list I want it to put itself into the the array at the position it was dropped at.
Just to be clear: I have an array of potential objects in a menu to the left. On the right I use $http to call to my API to retrieve a form that has fields all held in $scope. I want that potential object (like a textarea) to be dropped into that form's fields at the position dropped.
The jquery bit is straightforward but the non existent object to position in $scope array is the problem.
What I've tried:
I was close with mixing combing ui-sortable and $.draggable directive wrapper but my code isn't working very well.
Examples:
- KnockoutJS Example: http://bit.ly/15yrf8X
- jQuery demo: http://jqueryui.com/draggable/#sortable
Update 1:
I have made progress with a ui-sortable like directive combined with a directive that wraps $.draggable(), kinda ugly but works.
Update 2:
I have it working now but I grab the index from jquery and use php to slice it into that position and then reload the entire list. Talk about lame there must be a better way.
Update 3:
Here is a working example modularized for anyone's app.