From cc0a46d5cc6aebe98dd829f924983192256a7a2e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 7 Apr 2015 22:30:21 -0700 Subject: [PATCH] [Containment] Set validity in locator Set validity of selected location from locator control, to disallow creation when no valid location is selected (which is possible due to containment rules.) WTD-962. --- .../browse/src/creation/LocatorController.js | 9 +++++++++ platform/forms/src/MCTControl.js | 16 ++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/browse/src/creation/LocatorController.js b/platform/commonUI/browse/src/creation/LocatorController.js index 72d1736bee..bd727739c8 100644 --- a/platform/commonUI/browse/src/creation/LocatorController.js +++ b/platform/commonUI/browse/src/creation/LocatorController.js @@ -34,8 +34,17 @@ define( $scope.structure.validate(priorObject) ? priorObject : undefined ); + return; } } + + // Set validity + if ($scope.ngModelController) { + $scope.ngModelController.$setValidity( + 'composition', + !!$scope.treeModel.selectedObject + ); + } } // Initial state for the tree's model diff --git a/platform/forms/src/MCTControl.js b/platform/forms/src/MCTControl.js index 2197ac4424..f57ef05465 100644 --- a/platform/forms/src/MCTControl.js +++ b/platform/forms/src/MCTControl.js @@ -26,20 +26,18 @@ define( controlMap[control.key] = path; }); - function controller($scope) { - $scope.$watch("key", function (key) { + function link(scope, element, attrs, ngModelController) { + scope.$watch("key", function (key) { // Pass the template URL to ng-include via scope. - $scope.inclusion = controlMap[key]; + scope.inclusion = controlMap[key]; }); + scope.ngModelController = ngModelController; } return { // Only show at the element level restrict: "E", - // Use the included controller to populate scope - controller: controller, - // Use ng-include as a template; "inclusion" will be the real // template path template: '', @@ -47,6 +45,12 @@ define( // ngOptions is terminal, so we need to be higher priority priority: 1000, + // Get the ngModelController, so that controls can set validity + require: 'ngModel', + + // Link function + link: link, + // Pass through Angular's normal input field attributes scope: { // Used to choose which form control to use