Watching external changes on sortable model
Hi,
First of all, many thanks for sincere enhancements to this html5Sortable plugin. It has helped us a lot. Putting in one small issue we noted, and the fix we put for the same. You might want to add it to the main branch sometime.
It looks like external changes to the model of the htmlSortable Angularjs directive are not watched. So, if the value of the model is changed after the sortable is rendered (say, new divs or list elements are added as a result of another UI element action), those new elements do not have sortable properties (rather draggable class), and cannot be dragged.
So, we needed to add the following code in the html5Sortable.js to make it work for our case.
Existing code............................................ ngModel.$render = function() { $timeout(function () { element.sortable('reload'); }, 50); }; }
New code start
scope.$watch(attrs.ngModel, function() { $timeout(function () { element.sortable('reload'); }, 50); }, true); New code end.
// Create sortable
$(element).sortable(opts);
if (model) {
..............................................................Existing code.
Regards, --Parikshit N. Samant.
Sorry for the messed up formatting. I hope it is still understandable. BTW, the fiddle http://jsfiddle.net/xaxLC/ gives a sense of the issue. The initially loaded items are sortable. But if we add more using the button, those are not.
Regards, --Parikshit N. Samant.
Commited in 9f3d175953517daa3941076721c6dadbd4c2c29f.
Thanks!