diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 59c290da6d..a9a2bdbad0 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -31,7 +31,7 @@ { "key": "LocatorController", "implementation": "creation/LocatorController", - "depends": [ "$scope" ] + "depends": [ "$scope", "$timeout" ] }, { "key": "MenuArrowController", diff --git a/platform/commonUI/browse/src/creation/LocatorController.js b/platform/commonUI/browse/src/creation/LocatorController.js index d6335f9bd1..5e9dea8ed2 100644 --- a/platform/commonUI/browse/src/creation/LocatorController.js +++ b/platform/commonUI/browse/src/creation/LocatorController.js @@ -33,7 +33,7 @@ define( * @memberof platform/commonUI/browse * @constructor */ - function LocatorController($scope) { + function LocatorController($scope, $timeout) { // Populate values needed by the locator control. These are: // * rootObject: The top-level object, since we want to show // the full tree @@ -41,9 +41,19 @@ define( // used for bi-directional object selection. function setLocatingObject(domainObject, priorObject) { var context = domainObject && - domainObject.getCapability("context"); + domainObject.getCapability("context"), + contextRoot = context && context.getRoot(); + + if (contextRoot && contextRoot !== $scope.rootObject) { + $scope.rootObject = undefined; + // Update the displayed tree on a timeout to avoid + // an infinite digest exception. + $timeout(function () { + $scope.rootObject = + (context && context.getRoot()) || $scope.rootObject; + }, 0); + } - $scope.rootObject = (context && context.getRoot()) || $scope.rootObject; $scope.treeModel.selectedObject = domainObject; $scope.ngModel[$scope.field] = domainObject; @@ -52,10 +62,7 @@ define( $scope.structure && $scope.structure.validate) { if (!$scope.structure.validate(domainObject)) { - setLocatingObject( - $scope.structure.validate(priorObject) ? - priorObject : undefined - ); + setLocatingObject(priorObject, undefined); return; } }