mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
[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:
@ -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": [
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
<ng-form name="mctFormItem" ng-repeat="item in structure.items">
|
<span ng-controller="CompositeController as compositeCtrl">
|
||||||
<mct-control key="item.control"
|
<ng-form name="mctFormItem" ng-repeat="item in structure.items">
|
||||||
ng-model="ngModel[field]"
|
<mct-control key="item.control"
|
||||||
ng-required="ngRequired"
|
ng-model="ngModel[field]"
|
||||||
ng-pattern="ngPattern"
|
ng-required="ngRequired || compositeCtrl.isNonEmpty(ngModel[field])"
|
||||||
options="item.options"
|
ng-pattern="ngPattern"
|
||||||
structure="row"
|
options="item.options"
|
||||||
field="$index">
|
structure="row"
|
||||||
</mct-control>
|
field="$index">
|
||||||
<span class="composite-control-label">
|
</mct-control>
|
||||||
{{item.name}}
|
<span class="composite-control-label">
|
||||||
</span>
|
{{item.name}}
|
||||||
</ng-form>
|
</span>
|
||||||
|
</ng-form>
|
||||||
|
</span>
|
27
platform/forms/src/controllers/CompositeController.js
Normal file
27
platform/forms/src/controllers/CompositeController.js
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
Reference in New Issue
Block a user