Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 498b83b

Browse files
author
Josh Graber
committed
Merge pull request #89 from SamGraber/empty_is_valid
Set validFormat to true if the date is null or empty.
2 parents 65bff04 + 0beace7 commit 498b83b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/components/dateTime/dateTime.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { services } from 'typescript-angular-utilities';
1313

1414
import __dateTimeFormatStrings = services.date;
1515
import __validation = services.validation;
16+
import __object = services.object;
1617

1718
import {
1819
IComponentValidator,
@@ -81,9 +82,10 @@ export class DateTimeController {
8182
}
8283
}
8384

84-
dateTime.$inject = [services.moment.serviceName, __dateTimeFormatStrings.dateTimeFormatServiceName];
85+
dateTime.$inject = [services.moment.serviceName, __dateTimeFormatStrings.dateTimeFormatServiceName, __object.serviceName];
8586
function dateTime(moment: moment.MomentStatic
86-
, dateTimeFormatStrings: __dateTimeFormatStrings.IDateFormatStrings): angular.IDirective {
87+
, dateTimeFormatStrings: __dateTimeFormatStrings.IDateFormatStrings
88+
, object: __object.IObjectUtility): angular.IDirective {
8789
'use strict';
8890
return {
8991
restrict: 'E',
@@ -117,9 +119,9 @@ function dateTime(moment: moment.MomentStatic
117119
= dateTime.max != null ? dateTime.max : defaults.maxDate;
118120

119121
scope.$watch((): any => { return ngModel.$viewValue; }, (newValue: any): void => {
120-
if (newValue !== '') {
121-
dateTime.validFormat = moment(newValue).isValid();
122-
}
122+
dateTime.validFormat = object.isNullOrEmpty(newValue)
123+
? true
124+
: moment(newValue).isValid();
123125
});
124126

125127
// --- Implementation ---
@@ -154,6 +156,6 @@ function dateTime(moment: moment.MomentStatic
154156
};
155157
}
156158

157-
angular.module(moduleName, [services.moment.moduleName, services.date.moduleName, componentValidatorModuleName])
159+
angular.module(moduleName, [services.moment.moduleName, services.date.moduleName, componentValidatorModuleName, __object.moduleName])
158160
.directive(directiveName, dateTime)
159161
.controller(controllerName, DateTimeController);

0 commit comments

Comments
 (0)