angular-dragdrop icon indicating copy to clipboard operation
angular-dragdrop copied to clipboard

If I change data-drop value after the initialization the directive does not update its behavior.

Open akaNico opened this issue 9 years ago • 13 comments

akaNico avatar Jun 14 '16 22:06 akaNico

+1

bradrich avatar Jun 15 '16 17:06 bradrich

@mentalernie At least we know that it isn't something in our own code, because the demo here: http://codef0rmer.github.io/angular-dragdrop/#!/ctrl, doesn't work either. After you spell the correct character, the letters are supposed to not be draggable anymore.

bradrich avatar Jun 15 '16 18:06 bradrich

It would seem that the watcher for the data-drop and data-drag attributes is being killed prematurely. On lines 334 and 398 of the non-minified codebase is this:

if (killWatcher && angular.isDefined(newValue) && (angular.equals(attrs.drop, 'true') || angular.equals(attrs.drop, 'false'))) { killWatcher(); killWatcher = null; }

This is killing the watcher right after the initialization. Commenting/removing those blocks of code cause everything to work properly.

bradrich avatar Jun 15 '16 18:06 bradrich

EDIT: The fix that I mentioned above, leads to some weird issues, where droppable areas are not accepting the draggables. I am still investigating.

bradrich avatar Jun 15 '16 19:06 bradrich

@bradrich The annotated code above is for static attributes only such as data-drag="true" or data-drag="false".

@mentalernie If you want the behavior to be dynamic, you've to use a model and then use it in the DOM. For example, $scope.drag = false and data-drag="{{drag}}". Later when you update $scope.drag = true, the element will be draggable instantly.

codef0rmer avatar Jun 16 '16 17:06 codef0rmer

@codef0rmer I'm sorry but I was talking on "data-drop" Data-drag is ok.

akaNico avatar Jun 16 '16 18:06 akaNico

@codef0rmer @mentalernie is correct. The data-drop feature is not working with a dynamic {{...}} approach. Your demo that I pasted the link to above shows that.

bradrich avatar Jun 16 '16 18:06 bradrich

@bradrich @mentalernie How can I reproduce the issue with data-drop?

codef0rmer avatar Jun 17 '16 07:06 codef0rmer

+1 I am also experiencing this issue. @bradrich did you find a more stable solution than the one you posted above? @codef0rmer you can reproduce the issue from the demo link @bradrich posted above: http://codef0rmer.github.io/angular-dragdrop/#!/ctrl - after "Gollum" is spelt out it is still possible to rearrange the letters.

RichOnPeers avatar Jun 29 '16 12:06 RichOnPeers

I am having this issue as well.

eviltek2099 avatar Jul 08 '16 20:07 eviltek2099

Here is how I have been able to overcome the issue:

  • Comment out the if statement on line 334: https://github.com/codef0rmer/angular-dragdrop/blob/master/src/angular-dragdrop.js#L334
  • Comment out the if statement on line 398: https://github.com/codef0rmer/angular-dragdrop/blob/master/src/angular-dragdrop.js#L398
  • Replace line 331 (https://github.com/codef0rmer/angular-dragdrop/blob/master/src/angular-dragdrop.js#L331) with this:

dragSettings = scope.$eval(element.attr('jqyoui-draggable') || element.attr('data-jqyoui-draggable')) || {}; jqyouiOptions = scope.$eval(attrs.jqyouiOptions) || {}; element .draggable({disabled: true}) .draggable(jqyouiOptions);

  • Now that the code has moved down, replace line 399 with this:

dropSettings = scope.$eval($(element).attr('jqyoui-droppable') || $(element).attr('data-jqyoui-droppable')) || {}; jqyouiOptions = scope.$eval(attrs.jqyouiOptions) || {}; element .droppable({disabled: true}) .droppable(jqyouiOptions);

So far, I have had good luck with this implementation.

Notes:

  • The only reason that I have done a PR is this hasn't been fully tested or used outside of my own development.
  • Please understand that you assume your own liability using the aforementioned changes.

bradrich avatar Jul 09 '16 00:07 bradrich

For me, nor the drag is reacting to changes in the data-drag attribute. I have something like that:

$scope.textIsDraggable = function(index) {
   return $scope.draggableText == index;
 }

and then

<div class="card-text" ng-repeat="text in design.texts track by $index" ng-class="{'draggable': textIsDraggable($index)}" id="card-text-{{$index}}" data-drag="{{textIsDraggable($index)}}" data-index="{{$index}}" data-containment="offset" jqyoui-draggable="{ onStop: 'setDesignTextPosition' }"></div>

Yet if I change $scope.draggableText it won't react to changes and stay draggable (the attribute changes to false though, as I can see in the chrome inspector).

mxmzb avatar Aug 16 '16 09:08 mxmzb

I had the same problem, however I verified that @bradrich 's changes fixed my issue. I opened up a PR for them: https://github.com/codef0rmer/angular-dragdrop/pull/338

thejeff77 avatar Dec 04 '17 18:12 thejeff77