[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:
Victor Woeltjen 2015-06-03 14:20:45 -07:00
parent 2648f01966
commit fcd214ed60

View File

@ -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;