Skip to content

Commit

Permalink
Fix empty placeholder not responding to changes in the empty-placehol…
Browse files Browse the repository at this point in the history
…der-enabled attribute, and not respecting the initial value under some circumstances.
  • Loading branch information
adambowen committed May 3, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0ff0c53 commit 1769f6a
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/controllers/treeCtrl.js
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
};

this.resetEmptyElement = function () {
if ($scope.$nodesScope.$modelValue.length === 0 &&
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length === 0) &&
$scope.emptyPlaceholderEnabled) {
$element.append($scope.$emptyElm);
} else {
1 change: 1 addition & 0 deletions source/directives/uiTree.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
scope.$watch(attrs.emptyPlaceholderEnabled, function (val) {
if ((typeof val) == 'boolean') {
scope.emptyPlaceholderEnabled = val;
ctrl.resetEmptyElement();
}
});

8 changes: 8 additions & 0 deletions source/directives/uiTree.spec.js
Original file line number Diff line number Diff line change
@@ -46,11 +46,19 @@

var element = createElement('<div ui-tree empty-placeholder-enabled="enableEmptyPlaceholder"><div ui-tree-nodes="" ng-model="items"></div></div>');
expect(element.scope().emptyPlaceholderEnabled).toEqual(true);
expect(element.scope().$emptyElm.parent()).toEqual(element);

$scope.enableEmptyPlaceholder = false;
$scope.$digest();

expect(element.scope().emptyPlaceholderEnabled).toEqual(false);
expect(element.scope().$emptyElm.parent()).toNotEqual(element);
});

it('should hide the empty placeholder when ui-tree, ui-tree-nodes and empty-placeholder-enabled="false" are on the same element', function() {
var element = createElement('<div ui-tree empty-placeholder-enabled="false" ui-tree-nodes="" ng-model="items"></div>');
expect(element.scope().emptyPlaceholderEnabled).toEqual(false);
expect(element.scope().$emptyElm.parent()).toNotEqual(element);
});

it('should allow enabling / disabling dropping nodes', function () {

0 comments on commit 1769f6a

Please sign in to comment.