[Forms] Add CompositeController

Add a controller for composite controls; this is used
to flag contained controls as required when they have
been partially filled in (to treat entering one of two
such fields as invalid.) WTD-593.
This commit is contained in:
Victor Woeltjen
2014-12-03 16:07:46 -08:00
parent 6a6797bf53
commit 218f732dc2
3 changed files with 46 additions and 13 deletions

View File

@ -40,6 +40,10 @@
"key": "DateTimeController", "key": "DateTimeController",
"implementation": "controllers/DateTimeController.js", "implementation": "controllers/DateTimeController.js",
"depends": [ "$scope" ] "depends": [ "$scope" ]
},
{
"key": "CompositeController",
"implementation": "controllers/CompositeController.js"
} }
], ],
"templates": [ "templates": [

View File

@ -1,7 +1,8 @@
<ng-form name="mctFormItem" ng-repeat="item in structure.items"> <span ng-controller="CompositeController as compositeCtrl">
<ng-form name="mctFormItem" ng-repeat="item in structure.items">
<mct-control key="item.control" <mct-control key="item.control"
ng-model="ngModel[field]" ng-model="ngModel[field]"
ng-required="ngRequired" ng-required="ngRequired || compositeCtrl.isNonEmpty(ngModel[field])"
ng-pattern="ngPattern" ng-pattern="ngPattern"
options="item.options" options="item.options"
structure="row" structure="row"
@ -10,4 +11,5 @@
<span class="composite-control-label"> <span class="composite-control-label">
{{item.name}} {{item.name}}
</span> </span>
</ng-form> </ng-form>
</span>

View File

@ -0,0 +1,27 @@
/*global define*/
define(
[],
function () {
"use strict";
function CompositeController() {
function isDefined(element) {
return typeof element !== 'undefined';
}
function or(a, b) {
return a || b;
}
return {
isNonEmpty: function (value) {
return (value || []).map(isDefined).reduce(or, false);
}
};
}
return CompositeController;
}
);