Ability to disable drag based on scope variables?
First of all, thanks for the great library. Is there a way to make an element conditionally draggable? I am using ui.bootstrap.accordion and would like to make the elements sortable only when closed.
I've tried using the status.open model that the accordion populates as the expression for sv-element and it seems to have the desired effect, but probably just because it induces an error when I click inside an open panel (Uncaught TypeError: Object.keys called on non-object) which seems to be coming from here:
var opts = $parse($attrs.svElement)($scope);
opts = angular.extend({}, {
tolerance: 'pointer',
revert: 200,
containment: 'html'
}, opts);
The sv-element attribute value is supposed to be an angular expression that evaluates to an object. Like this: sv-element="{revert: 100}". If you want an element to be conditionally draggable, then i'd suggest using an sv-handle and hiding it when the element is expanded.
That doesn't seem to work; the entire the accordion panel is still draggable even when I add sv-handle to an inner element.
I ended up adding my own sv-prevent attribute which gets the interpolated value of the accordion's status.open and then in onMousedown I added another early return if $attrs.svPrevent is true.
Might be related to #18 which will be fixed in a minute
I would also like to conditionally enable/disable the drag and drop ability. I don't see this issue as resolved, so how is it closed?
I have a ng-repeat that creates a list of items that can be expanded/collapsed. I have an sv-handle, but I only want to show the handle (and therefore enable dragging) when all items are collapsed. However, if I hide the element with the sv-handle when any of the items are expanded, the sv-handle essentially does not exist, and you can then drag any item by clicking on it anywhere.
To get around this, temporarily, I've got something like this:
It works, but it's not so elegant. An sv-enable (or sv-disable) would be really nice. If there is a way to do this, then some updated documentation would be really nice.
Thanks
I've updated the demo. Check out http://kamilkp.github.io/angular-sortable-view/#?tab=3
There is a checkbox to hide the handles. Is that the desired behavior for you?
Thanks for the update. It's sort of what i meant, but i needed something a little more complicated. i had some code snippet in my previous comment, but it looks like it didn't show. It's ok though. I've figured out how to make it work.
I am having 1 other problem though. Here's the scenario. Let's say I have a list of items, 1,2,3,4 Once an item is complete, it cannot be draggable. That's good, I've got that working. So let's say item 1 is complete. I need to prevent 2,3, or 4 from being dragged above 1. I've been trying to get the sv-on-start or sv-on-stop to work, with no luck and I'm not even sure they will help. Is there a way to do that?
Thanks, Jason
You'd have to render item 1 out of the sv-part container. Essentially the "complete" elements would have to be renered as not part of the sortable component and manipulate some positioning to get the visual effect you need. Is it something e.g. a jQuery sortable supports?
That is exactly what I suspected. I'll figure it out. I was hoping for an easier solution. Maybe an sv-disable-drag-above and sv-disable-drag-below attribute would be awesome in the future ? ;)
Thanks for your replies.
I'd also love to see an sv-enabled="someScopeVar", as we want to do things like disable drag/drop re-ordering when a filter is applied, etc. We'd rather not use a handle as that's not super user friendly for our scenario, but we will for now. :)
@dmackerman in your case you could just add a
<div ng-if="noDrag" sv-handle style="display: none"></div>
to disable dragging, and still have full element dragging when enabled