From 024409e4d4904ccc39684f8cb698c1cb2b88044c Mon Sep 17 00:00:00 2001 From: Godson Ukpere Date: Fri, 21 Jul 2017 23:42:45 +0100 Subject: [PATCH 1/4] fix(ClearModels): Don't clear models on init This makes the field dirty by default. --- src/ng2-datetime/ng2-datetime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng2-datetime/ng2-datetime.ts b/src/ng2-datetime/ng2-datetime.ts index 2769dd9e..61426a71 100644 --- a/src/ng2-datetime/ng2-datetime.ts +++ b/src/ng2-datetime/ng2-datetime.ts @@ -129,7 +129,7 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro this.updateModel(this.date); }, 0); } else { - this.clearModels(); + // this.clearModels(); } } From b69966eba91d97492a5b94dec58858d269681f5c Mon Sep 17 00:00:00 2001 From: Godson Ukpere Date: Fri, 21 Jul 2017 23:54:43 +0100 Subject: [PATCH 2/4] chore(Validation): Treat inputs as date Treat input as date and compare the date's parsing with 'Invalid date'. --- src/ng2-datetime/ng2-datetime.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ng2-datetime/ng2-datetime.ts b/src/ng2-datetime/ng2-datetime.ts index 61426a71..0b24a57c 100644 --- a/src/ng2-datetime/ng2-datetime.ts +++ b/src/ng2-datetime/ng2-datetime.ts @@ -123,13 +123,13 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro } writeValue(value: any) { - this.date = value; + this.date = new Date(value); if (isDate(this.date)) { setTimeout(() => { this.updateModel(this.date); }, 0); } else { - // this.clearModels(); + this.clearModels(); } } @@ -266,5 +266,5 @@ function uniqueId(prefix: string): string { } function isDate(obj: any) { - return Object.prototype.toString.call(obj) === '[object Date]'; + return obj.toString() !== 'Invalid date'; } From 54bf1e6e9cb50b4ec463a941bf5e33d8117c8850 Mon Sep 17 00:00:00 2001 From: Godson Ukpere Date: Fri, 21 Jul 2017 23:57:32 +0100 Subject: [PATCH 3/4] Update ng2-datetime.ts --- src/ng2-datetime/ng2-datetime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng2-datetime/ng2-datetime.ts b/src/ng2-datetime/ng2-datetime.ts index 0b24a57c..0e1656b7 100644 --- a/src/ng2-datetime/ng2-datetime.ts +++ b/src/ng2-datetime/ng2-datetime.ts @@ -266,5 +266,5 @@ function uniqueId(prefix: string): string { } function isDate(obj: any) { - return obj.toString() !== 'Invalid date'; + return obj.toString() !== 'Invalid Date'; } From 1965b0c04f3e961ac03fba135f7c9b1a9e8a07be Mon Sep 17 00:00:00 2001 From: Godson Ukpere Date: Sat, 22 Jul 2017 04:07:16 +0100 Subject: [PATCH 4/4] chore(CQ): Add CQ fixes --- src/ng2-datetime/ng2-datetime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng2-datetime/ng2-datetime.ts b/src/ng2-datetime/ng2-datetime.ts index 0e1656b7..817b37db 100644 --- a/src/ng2-datetime/ng2-datetime.ts +++ b/src/ng2-datetime/ng2-datetime.ts @@ -266,5 +266,5 @@ function uniqueId(prefix: string): string { } function isDate(obj: any) { - return obj.toString() !== 'Invalid Date'; + return obj && obj.toString() !== 'Invalid Date'; }