[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.
This commit is contained in:
Victor Woeltjen 2015-04-07 22:30:21 -07:00
parent 0550e09344
commit cc0a46d5cc
2 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -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: '<ng-include src="inclusion"></ng-include>',
@ -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