From 972db8a8dd9a884e6a6c5e133553185c7533d759 Mon Sep 17 00:00:00 2001 From: Philipp Jenni Date: Mon, 18 Nov 2024 09:01:47 +0100 Subject: [PATCH] fix: Date Validation fixed --- .../src/app/datetime/datetime.component.html | 149 ++++++++++++++---- .../src/app/datetime/datetime.component.ts | 21 ++- .../formreactive/reactiveform.component.html | 2 + .../formreactive/reactiveform.component.ts | 16 +- .../src/app/datetime/datetime.component.html | 7 + .../src/app/datetime/datetime.component.ts | 21 ++- .../formreactive/reactiveform.component.html | 2 + .../formreactive/reactiveform.component.ts | 16 +- .../src/app/datetime/datetime.component.html | 7 + .../src/app/datetime/datetime.component.ts | 21 ++- .../formreactive/reactiveform.component.html | 2 + .../formreactive/reactiveform.component.ts | 16 +- .../src/common/basedatetimecontrol.ts | 2 +- .../sac-common/src/validation/isDateValid.ts | 17 +- 14 files changed, 239 insertions(+), 60 deletions(-) diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.html b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.html index da49b6c69..ee9c96448 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.html +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.html @@ -6,42 +6,123 @@

DateTime

- - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.ts b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.ts index 29590fb03..1e2fd0a61 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.ts +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/datetime/datetime.component.ts @@ -6,29 +6,38 @@ import { SacFormDirective } from '@simpleangularcontrols/sac-bootstrap3'; templateUrl: './datetime.component.html', }) export class DemoDatetimeComponent { + // #region Properties + + @ViewChild('myForm') public myForm: SacFormDirective; + public values: any = { datum1: '', - datum2: Date.now(), + datum2: new Date(Date.now()), datum3: '', datum4: '', datum5: '', - time1: '', + time1: new Date(Date.now()), time2: '', time3: '', time4: '', - time5: Date.now(), + time5: new Date(Date.now()), time6: '', - datumzeit1: Date.now(), - datumzeit2: '', + datumzeit1: new Date(Date.now()), + datumzeit2: '2024-11-22T17:10:00+01:00', datumzeit3: '', datumzeit4: '', datumzeit5: '', + datumzeit6: '2024-11-18T07:54:28.870Z', }; - @ViewChild('myForm') myForm: SacFormDirective; + // #endregion Properties + + // #region Public Methods public debugAction(): void { this.myForm.markAsTouched(); alert('Action'); } + + // #endregion Public Methods } diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.html b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.html index 46a2895c7..6aa45db75 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.html +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.html @@ -1,5 +1,7 @@

Reactive Form

+ +
Full Summary
diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.ts b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.ts index 3a98ab364..63f98274b 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.ts +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap3/src/app/formreactive/reactiveform.component.ts @@ -7,14 +7,16 @@ import { Validation } from '@simpleangularcontrols/sac-common'; templateUrl: './reactiveform.component.html', }) export class DemoRectiveFormComponent { + // #region Properties + // formfield1 = new FormControl('', Validation.required('VALIDATION_ERROR_REQUIRED','VALIDATION_ERROR_SUMMARY_REQUIRED')); - baseForm = new FormGroup({ + public baseForm = new FormGroup({ inputvalue: new FormControl(''), checkboxvalue: new FormControl(true), listvalue: new FormControl(''), dropdownvalue: new FormControl(''), radiobuttonvalue: new FormControl('1'), - datetimevalue: new FormControl(''), + datetimevalue: new FormControl('2024-11-22T17:10:00+01:00'), partial: new FormGroup({ part1: new FormGroup({ inputvalue2: new FormControl(''), @@ -28,4 +30,14 @@ export class DemoRectiveFormComponent { }), }), }); + + // #endregion Properties + + // #region Public Methods + + public change(): void { + this.baseForm.patchValue({ datetimevalue: '2024-11-23T17:11:00+01:00' }); + } + + // #endregion Public Methods } diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/datetime/datetime.component.html b/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/datetime/datetime.component.html index 5d4452a43..9084dc7c9 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/datetime/datetime.component.html +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/datetime/datetime.component.html @@ -122,6 +122,13 @@

DateTime

disabled="true" > + + Reactive Form + +
Full Summary
diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/formreactive/reactiveform.component.ts b/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/formreactive/reactiveform.component.ts index 3a98ab364..63f98274b 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/formreactive/reactiveform.component.ts +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap4/src/app/formreactive/reactiveform.component.ts @@ -7,14 +7,16 @@ import { Validation } from '@simpleangularcontrols/sac-common'; templateUrl: './reactiveform.component.html', }) export class DemoRectiveFormComponent { + // #region Properties + // formfield1 = new FormControl('', Validation.required('VALIDATION_ERROR_REQUIRED','VALIDATION_ERROR_SUMMARY_REQUIRED')); - baseForm = new FormGroup({ + public baseForm = new FormGroup({ inputvalue: new FormControl(''), checkboxvalue: new FormControl(true), listvalue: new FormControl(''), dropdownvalue: new FormControl(''), radiobuttonvalue: new FormControl('1'), - datetimevalue: new FormControl(''), + datetimevalue: new FormControl('2024-11-22T17:10:00+01:00'), partial: new FormGroup({ part1: new FormGroup({ inputvalue2: new FormControl(''), @@ -28,4 +30,14 @@ export class DemoRectiveFormComponent { }), }), }); + + // #endregion Properties + + // #region Public Methods + + public change(): void { + this.baseForm.patchValue({ datetimevalue: '2024-11-23T17:11:00+01:00' }); + } + + // #endregion Public Methods } diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/datetime/datetime.component.html b/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/datetime/datetime.component.html index 5d4452a43..9084dc7c9 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/datetime/datetime.component.html +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/datetime/datetime.component.html @@ -122,6 +122,13 @@

DateTime

disabled="true" > + + Reactive Form + +
Full Summary
diff --git a/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/formreactive/reactiveform.component.ts b/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/formreactive/reactiveform.component.ts index 3a98ab364..63f98274b 100644 --- a/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/formreactive/reactiveform.component.ts +++ b/ch.jnetwork.sac-controls/projects/demo-bootstrap5/src/app/formreactive/reactiveform.component.ts @@ -7,14 +7,16 @@ import { Validation } from '@simpleangularcontrols/sac-common'; templateUrl: './reactiveform.component.html', }) export class DemoRectiveFormComponent { + // #region Properties + // formfield1 = new FormControl('', Validation.required('VALIDATION_ERROR_REQUIRED','VALIDATION_ERROR_SUMMARY_REQUIRED')); - baseForm = new FormGroup({ + public baseForm = new FormGroup({ inputvalue: new FormControl(''), checkboxvalue: new FormControl(true), listvalue: new FormControl(''), dropdownvalue: new FormControl(''), radiobuttonvalue: new FormControl('1'), - datetimevalue: new FormControl(''), + datetimevalue: new FormControl('2024-11-22T17:10:00+01:00'), partial: new FormGroup({ part1: new FormGroup({ inputvalue2: new FormControl(''), @@ -28,4 +30,14 @@ export class DemoRectiveFormComponent { }), }), }); + + // #endregion Properties + + // #region Public Methods + + public change(): void { + this.baseForm.patchValue({ datetimevalue: '2024-11-23T17:11:00+01:00' }); + } + + // #endregion Public Methods } diff --git a/ch.jnetwork.sac-controls/projects/sac-common/src/common/basedatetimecontrol.ts b/ch.jnetwork.sac-controls/projects/sac-common/src/common/basedatetimecontrol.ts index 3b6b0e216..c9866f67b 100644 --- a/ch.jnetwork.sac-controls/projects/sac-common/src/common/basedatetimecontrol.ts +++ b/ch.jnetwork.sac-controls/projects/sac-common/src/common/basedatetimecontrol.ts @@ -112,7 +112,7 @@ export abstract class SacBaseDateTimeControl /** * JSON Date String in ein UTC DateTime Object konvertieren, welches vom Control verwendete werden kann */ - public getDate(timestamp) { + public getDate(timestamp): moment.Moment { const date = new Date(timestamp); const year = date.getUTCFullYear(); const month = date.getUTCMonth(); diff --git a/ch.jnetwork.sac-controls/projects/sac-common/src/validation/isDateValid.ts b/ch.jnetwork.sac-controls/projects/sac-common/src/validation/isDateValid.ts index f98d4ce06..c353e8581 100644 --- a/ch.jnetwork.sac-controls/projects/sac-common/src/validation/isDateValid.ts +++ b/ch.jnetwork.sac-controls/projects/sac-common/src/validation/isDateValid.ts @@ -1,18 +1,33 @@ -import { Moment } from 'moment'; import * as moment_ from 'moment'; +import { Moment } from 'moment'; + +// #region Variables + /** * Moment */ export const moment = moment_['default']; +// #endregion Variables + +// #region Functions + export function isDateValid(value: any, format: string) { // NULL ist gültig if (value === null || value === undefined || value === '') { return true; } + // Check is Iso Date (From API Call) + if (moment(value, moment_.ISO_8601, true).isValid()) { + return true; + } + let date: Moment = moment(value, [format], true); date = date.utc(); return date.isValid(); } + +// #endregion Functions +