Compare commits

...

2 Commits

Author SHA1 Message Date
5b0c0e1278 [Time Conductor] Validate start/end times 2016-01-11 15:08:56 -08:00
e5cf419697 [Time Conductor] Attach custom validators
Attach validation functions passed into mct-control instances
as custom validators (in the  object of ngModelController)
to integrate cleanly with normal Angular form validation.

Supports usage of comparative validation logic to visually display
form elements in the time conductor as invalid when bounds
overlap (e.g. start is before end.)

https://github.com/nasa/openmctweb/issues/325
2016-01-11 15:03:53 -08:00
3 changed files with 20 additions and 2 deletions

View File

@ -25,7 +25,7 @@
<span class="l-time-range-inputs-elem ui-symbol type-icon">&#x43;</span>
<span class="l-time-range-input">
<mct-control key="'datetime-field'"
structure="{ format: parameters.format }"
structure="{ format: parameters.format, validate: validateStart }"
ng-model="formModel"
ng-blur="updateBoundsFromForm()"
field="'start'"
@ -37,7 +37,7 @@
<span class="l-time-range-input" ng-controller="ToggleController as t2">
<mct-control key="'datetime-field'"
structure="{ format: parameters.format }"
structure="{ format: parameters.format, validate: validateEnd }"
ng-model="formModel"
ng-blur="updateBoundsFromForm()"
field="'end'"

View File

@ -240,6 +240,14 @@ define(
};
}
function validateStart(startValue) {
return startValue <= $scope.ngModel.outer.end - outerMinimumSpan;
}
function validateEnd(endValue) {
return endValue >= $scope.ngModel.outer.start + outerMinimumSpan;
}
$scope.startLeftDrag = startLeftDrag;
$scope.startRightDrag = startRightDrag;
$scope.startMiddleDrag = startMiddleDrag;
@ -249,6 +257,9 @@ define(
$scope.updateBoundsFromForm = updateBoundsFromForm;
$scope.validateStart = validateStart;
$scope.validateEnd = validateEnd;
$scope.ticks = [];
// Initialize scope to defaults

View File

@ -54,6 +54,13 @@ define(
// Pass the template URL to ng-include via scope.
scope.inclusion = controlMap[key];
});
scope.$watch("structure.validate", function (validate) {
if (typeof validate === 'function') {
ngModelController.$validators.custom = validate;
} else {
delete ngModelController.$validators.custom;
}
});
scope.ngModelController = ngModelController;
}