diff --git a/platform/commonUI/general/res/templates/controls/datetime-field.html b/platform/commonUI/general/res/templates/controls/datetime-field.html
index e9b394c530..18eb9ec46d 100644
--- a/platform/commonUI/general/res/templates/controls/datetime-field.html
+++ b/platform/commonUI/general/res/templates/controls/datetime-field.html
@@ -24,7 +24,11 @@
+ ng-class="{
+ error: textInvalid ||
+ (structure.validate &&
+ !structure.validate(ngModel[field]))
+ }">
C
= start + outerMinimumSpan) {
+ $scope.ngModel = $scope.ngModel || {};
+ $scope.ngModel.outer = { start: start, end: end };
+ }
+ }
+
+ function validateStart(startValue) {
+ return startValue <= $scope.formModel.end - outerMinimumSpan;
+ }
+
+ function validateEnd(endValue) {
+ return endValue >= $scope.formModel.start + outerMinimumSpan;
}
$scope.startLeftDrag = startLeftDrag;
@@ -249,6 +244,9 @@ define(
$scope.updateBoundsFromForm = updateBoundsFromForm;
+ $scope.validateStart = validateStart;
+ $scope.validateEnd = validateEnd;
+
$scope.ticks = [];
// Initialize scope to defaults
diff --git a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js
index 861f28ed45..efff87651f 100644
--- a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js
+++ b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js
@@ -91,6 +91,24 @@ define(
.toHaveBeenCalledWith("ngModel", jasmine.any(Function));
});
+ it("exposes start time validator", function () {
+ var testValue = 42000000;
+ mockScope.formModel = { end: testValue };
+ expect(mockScope.validateStart(testValue + 1))
+ .toBe(false);
+ expect(mockScope.validateStart(testValue - 60 * 60 * 1000 - 1))
+ .toBe(true);
+ });
+
+ it("exposes end time validator", function () {
+ var testValue = 42000000;
+ mockScope.formModel = { start: testValue };
+ expect(mockScope.validateEnd(testValue - 1))
+ .toBe(false);
+ expect(mockScope.validateEnd(testValue + 60 * 60 * 1000 + 1))
+ .toBe(true);
+ });
+
describe("when changes are made via form entry", function () {
beforeEach(function () {
mockScope.ngModel = {
@@ -194,26 +212,6 @@ define(
fireWatchCollection("ngModel", mockScope.ngModel);
});
- it("enforces a minimum outer span", function () {
- mockScope.ngModel.outer.end =
- mockScope.ngModel.outer.start - DAY * 100;
- fireWatch(
- "ngModel.outer.end",
- mockScope.ngModel.outer.end
- );
- expect(mockScope.ngModel.outer.end)
- .toBeGreaterThan(mockScope.ngModel.outer.start);
-
- mockScope.ngModel.outer.start =
- mockScope.ngModel.outer.end + DAY * 100;
- fireWatch(
- "ngModel.outer.start",
- mockScope.ngModel.outer.start
- );
- expect(mockScope.ngModel.outer.end)
- .toBeGreaterThan(mockScope.ngModel.outer.start);
- });
-
it("enforces a minimum inner span when outer span changes", function () {
mockScope.ngModel.outer.end =
mockScope.ngModel.outer.start - DAY * 100;