From 17af6e651911ef30bb4fe551b66431bbd2b7c3ae Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 6 Aug 2024 10:49:17 +0100 Subject: [PATCH] Add resetErrors method --- .../carbon-estimator-form.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.component.ts b/src/app/carbon-estimator-form/carbon-estimator-form.component.ts index fb9f298..2b45a4f 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.component.ts +++ b/src/app/carbon-estimator-form/carbon-estimator-form.component.ts @@ -171,8 +171,7 @@ export class CarbonEstimatorFormComponent implements OnInit { this.errorSummary?.summary.nativeElement.focus(); return; } - this.validationErrors = []; - this.showErrorSummary = false; + this.resetErrors(); const formValue = this.estimatorForm.getRawValue(); if (formValue.onPremise.serverLocation === 'unknown') { formValue.onPremise.serverLocation = 'WORLD'; @@ -188,8 +187,7 @@ export class CarbonEstimatorFormComponent implements OnInit { public resetForm() { this.estimatorForm.reset(); - this.validationErrors = []; - this.showErrorSummary = false; + this.resetErrors(); this.formReset.emit(); } @@ -227,4 +225,9 @@ export class CarbonEstimatorFormComponent implements OnInit { return validationErrors; } + + private resetErrors() { + this.validationErrors = []; + this.showErrorSummary = false; + } }