mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Forms] Show initial value in datetime control
Initialize value for datetime control based on available data, and keep up-to-date with changes from UI. Supports clocks/timers, which use datetime as an entry field, WTD-1221.
This commit is contained in:
parent
2648f01966
commit
fcd214ed60
@ -68,13 +68,35 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
function updateDateTime(value) {
|
||||
var m;
|
||||
if (value !== undefined) {
|
||||
m = moment.utc(value);
|
||||
$scope.datetime = {
|
||||
date: m.format(DATE_FORMAT),
|
||||
hour: m.format("H"),
|
||||
min: m.format("m"),
|
||||
sec: m.format("s")
|
||||
};
|
||||
} else {
|
||||
$scope.datetime = {};
|
||||
}
|
||||
}
|
||||
|
||||
// ...and update form values when actual field in model changes
|
||||
$scope.$watch("ngModel[field]", updateDateTime);
|
||||
|
||||
// Update value whenever any field changes.
|
||||
$scope.$watch("datetime.date", update);
|
||||
$scope.$watch("datetime.hour", update);
|
||||
$scope.$watch("datetime.min", update);
|
||||
$scope.$watch("datetime.sec", update);
|
||||
|
||||
$scope.datetime = {};
|
||||
// Initialize forms values
|
||||
updateDateTime(
|
||||
($scope.ngModel && $scope.field) ?
|
||||
$scope.ngModel[$scope.field] : undefined
|
||||
);
|
||||
}
|
||||
|
||||
return DateTimeController;
|
||||
|
Loading…
x
Reference in New Issue
Block a user