From 471bf6b2523c8a043a8df620ae117a1548c6ac6b Mon Sep 17 00:00:00 2001 From: Sam Warren Date: Fri, 17 Jan 2025 18:15:44 -0800 Subject: [PATCH 1/3] DEVOPS-175-Patch: Update error messaging --- .../support-details.component.html | 16 +++++++++-- .../support-details.component.ts | 28 ++++--------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html index c968abcf2..d590339ea 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html @@ -256,7 +256,13 @@ supportDetailsFormControl.fromTime.invalid && supportDetailsFormControl.fromTime.hasError('required') ) { - From Time is required + From Time is required + } + @if ( + supportDetailsFormControl.fromTime.invalid && + supportDetailsFormControl.fromTime.hasError('invalidTaskTime') + ) { + Time must fall within task start and end times } @if ( supportDetailsFormControl.fromTime.invalid && @@ -338,7 +344,13 @@ supportDetailsFormControl.toTime.invalid && supportDetailsFormControl.toTime.hasError('required') ) { - To Time Required + To Time is required + } + @if ( + supportDetailsFormControl.toTime.invalid && + supportDetailsFormControl.toTime.hasError('invalidTaskTime') + ) { + Time must fall within task start and end times } @if ( supportDetailsFormControl.toTime.invalid && diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 0df027385..0b1e6f01b 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -153,7 +153,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { let isValid = false; const error = { invalidTaskDateTime: true }; const otherControl = this.supportDetailsForm?.get(other); - // no need to validate if one of the controls does not have a value + if ( control?.value === null || control?.value === '' || @@ -178,31 +178,13 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { isValid = moment(controlDate).isBetween(from, to, 'm', '[]'); } else isValid = true; } + if (!isValid) { otherControl?.setErrors(error); - control?.setErrors(error); - } else { - if (control.errors) { - const errors = { ...control.errors }; // Copy the errors object - delete errors['invalidTaskDateTime']; // Remove the specific error - - if (Object.keys(errors).length === 0) { - control.setErrors(null); // No errors left, set to null - } else { - control.setErrors(errors); // Set the modified errors object - } - if (otherControl.errors) { - const errors = { ...otherControl.errors }; // Copy the errors object - delete errors['invalidTaskDateTime']; // Remove the specific error - - if (Object.keys(errors).length === 0) { - otherControl.setErrors(null); // No errors left, set to null - } else { - otherControl.setErrors(errors); // Set the modified errors object - } - } - } + return error; // Return the error instead of null } + + otherControl?.setErrors(null); return null; }; } From 8db4756df0cb595c342210023309f1db0da05438 Mon Sep 17 00:00:00 2001 From: Sam Warren Date: Fri, 17 Jan 2025 18:56:41 -0800 Subject: [PATCH 2/3] DEVOPS-175-Patch: Updates to form validation --- .../support-details.component.html | 36 ++++--------------- .../support-details.component.ts | 13 ++++--- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html index d590339ea..fe4676e6d 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.html @@ -224,15 +224,9 @@ @if ( supportDetailsFormControl.fromDate.invalid && - supportDetailsFormControl.fromDate.hasError('invalidDate') + supportDetailsFormControl.fromDate.hasError('invalidTaskDate') ) { - Please enter a valid date - } - @if ( - supportDetailsFormControl.fromDate.invalid && - supportDetailsFormControl.fromDate.hasError('invalidTaskDateTime') - ) { - Date/time must fall within the task dates + Date must fall within the task dates } @if ( supportDetailsFormControl.fromDate.invalid && @@ -262,13 +256,7 @@ supportDetailsFormControl.fromTime.invalid && supportDetailsFormControl.fromTime.hasError('invalidTaskTime') ) { - Time must fall within task start and end times - } - @if ( - supportDetailsFormControl.fromTime.invalid && - supportDetailsFormControl.fromTime.hasError('invalidTaskDateTime') - ) { - Date/time must fall within the task dates + Time must fall within the task dates } @@ -312,15 +300,9 @@ @if ( supportDetailsFormControl.toDate.invalid && - supportDetailsFormControl.toDate.hasError('invalidDate') + supportDetailsFormControl.toDate.hasError('invalidTaskDate') ) { - Please enter a valid date - } - @if ( - supportDetailsFormControl.toDate.invalid && - supportDetailsFormControl.toDate.hasError('invalidTaskDateTime') - ) { - Date/time must fall within the task dates + Date must fall within the task dates } @if ( supportDetailsFormControl.toDate.invalid && @@ -350,13 +332,7 @@ supportDetailsFormControl.toTime.invalid && supportDetailsFormControl.toTime.hasError('invalidTaskTime') ) { - Time must fall within task start and end times - } - @if ( - supportDetailsFormControl.toTime.invalid && - supportDetailsFormControl.toTime.hasError('invalidTaskDateTime') - ) { - Date/time must fall within the task dates + Time must fall within the task dates } diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 0b1e6f01b..aa5c4b752 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -151,7 +151,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { compareTaskDateTimeValidator({ controlType, other }: { controlType: 'date' | 'time'; other: string }): ValidatorFn { return (control: AbstractControl): ValidationErrors | null => { let isValid = false; - const error = { invalidTaskDateTime: true }; + const error = controlType === 'date' ? { invalidTaskDate: true } : { invalidTaskTime: true }; const otherControl = this.supportDetailsForm?.get(other); if ( @@ -174,14 +174,19 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { if (this.evacueeSessionService?.evacFile?.task?.from && this.evacueeSessionService?.evacFile?.task?.to) { const from = moment(this.evacueeSessionService?.evacFile?.task?.from); const to = moment(this.evacueeSessionService?.evacFile?.task?.to); - - isValid = moment(controlDate).isBetween(from, to, 'm', '[]'); + const current = moment(controlDate); + + if (current.isSame(to, 'day') && current.isAfter(to)) { + isValid = false; + } else { + isValid = current.isBetween(from, to, 'm', '[]'); + } } else isValid = true; } if (!isValid) { otherControl?.setErrors(error); - return error; // Return the error instead of null + return error; } otherControl?.setErrors(null); From 36ea6846fbf8a940cce0eef9180fd1d5dcc15e83 Mon Sep 17 00:00:00 2001 From: Sam Warren Date: Fri, 17 Jan 2025 19:34:07 -0800 Subject: [PATCH 3/3] DEVOPS-175-Patch: Lint fix --- .../support-details/support-details.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts index 8cc01e1c6..c9c196e15 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/support-components/support-details/support-details.component.ts @@ -176,7 +176,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy { const from = moment(this.evacueeSessionService?.evacFile?.task?.from); const to = moment(this.evacueeSessionService?.evacFile?.task?.to); const current = moment(controlDate); - + if (current.isSame(to, 'day') && current.isAfter(to)) { isValid = false; } else {