mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 03:06:54 +00:00
[Time Conductor] Validate numeric date-time fields
Allow injection of a validator for numeric values of the date-time fields, to allow for these to be displayed as invalid in cases where the text itself may be parsed but the resulting value is not valid (e.g. when start is greater than end.) https://github.com/nasa/openmctweb/issues/325
This commit is contained in:
parent
019e04f9ab
commit
07c407edea
@ -24,7 +24,7 @@
|
||||
<input type="text"
|
||||
ng-model="textValue"
|
||||
ng-blur="restoreTextValue(); ngBlur()"
|
||||
ng-class="{ error: textInvalid }">
|
||||
ng-class="{ error: textInvalid, test: valueInvalid }">
|
||||
</input>
|
||||
<a class="ui-symbol icon icon-calendar"
|
||||
ng-if="structure.format === 'utc' || !structure.format"
|
||||
|
@ -26,6 +26,10 @@ define(
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
function ACCEPT() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller to support the date-time entry field.
|
||||
*
|
||||
@ -44,7 +48,8 @@ define(
|
||||
* format has been otherwise specified
|
||||
*/
|
||||
function DateTimeFieldController($scope, formatService, defaultFormat) {
|
||||
var formatter = formatService.getFormat(defaultFormat);
|
||||
var formatter = formatService.getFormat(defaultFormat),
|
||||
validate = ACCEPT;
|
||||
|
||||
function updateFromModel(value) {
|
||||
// Only reformat if the value is different from user
|
||||
@ -59,10 +64,12 @@ define(
|
||||
}
|
||||
|
||||
function updateFromView(textValue) {
|
||||
var newValue;
|
||||
$scope.textInvalid = !formatter.validate(textValue);
|
||||
if (!$scope.textInvalid) {
|
||||
$scope.ngModel[$scope.field] =
|
||||
formatter.parse(textValue);
|
||||
newValue = formatter.parse(textValue);
|
||||
$scope.valueInvalid = !validate(newValue);
|
||||
$scope.ngModel[$scope.field] = newValue;
|
||||
$scope.lastValidValue = $scope.textValue;
|
||||
}
|
||||
}
|
||||
@ -82,6 +89,10 @@ define(
|
||||
updateFromModel($scope.ngModel[$scope.field]);
|
||||
}
|
||||
|
||||
function setValidator(newValidator) {
|
||||
validate = newValidator || ACCEPT;
|
||||
}
|
||||
|
||||
function restoreTextValue() {
|
||||
$scope.textValue = $scope.lastValidValue;
|
||||
updateFromView($scope.textValue);
|
||||
@ -95,7 +106,7 @@ define(
|
||||
$scope.$watch('ngModel[field]', updateFromModel);
|
||||
$scope.$watch('pickerModel.value', updateFromPicker);
|
||||
$scope.$watch('textValue', updateFromView);
|
||||
|
||||
$scope.$watch('structure.validate', setValidator);
|
||||
}
|
||||
|
||||
return DateTimeFieldController;
|
||||
|
Loading…
Reference in New Issue
Block a user