From 63bd95ea1ea4a3b8e0f322a6509e720c1a4651b4 Mon Sep 17 00:00:00 2001 From: sercan Date: Thu, 4 Oct 2018 12:21:46 +0300 Subject: [PATCH] (Coming Soon) Simplified the form error messages --- .../coming-soon/coming-soon.component.html | 5 +- .../coming-soon/coming-soon.component.ts | 63 +------------------ 2 files changed, 5 insertions(+), 63 deletions(-) diff --git a/src/app/main/pages/coming-soon/coming-soon.component.html b/src/app/main/pages/coming-soon/coming-soon.component.html index 08995503..fc44953e 100644 --- a/src/app/main/pages/coming-soon/coming-soon.component.html +++ b/src/app/main/pages/coming-soon/coming-soon.component.html @@ -28,10 +28,11 @@ Email - + Email is required - + Please enter a valid email address diff --git a/src/app/main/pages/coming-soon/coming-soon.component.ts b/src/app/main/pages/coming-soon/coming-soon.component.ts index 5b42df46..06c5d8b6 100644 --- a/src/app/main/pages/coming-soon/coming-soon.component.ts +++ b/src/app/main/pages/coming-soon/coming-soon.component.ts @@ -1,7 +1,5 @@ -import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; import { FuseConfigService } from '@fuse/services/config.service'; import { fuseAnimations } from '@fuse/animations'; @@ -13,13 +11,9 @@ import { fuseAnimations } from '@fuse/animations'; encapsulation: ViewEncapsulation.None, animations : fuseAnimations }) -export class ComingSoonComponent implements OnInit, OnDestroy +export class ComingSoonComponent implements OnInit { comingSoonForm: FormGroup; - comingSoonFormErrors: any; - - // Private - private _unsubscribeAll: Subject; /** * Constructor @@ -49,14 +43,6 @@ export class ComingSoonComponent implements OnInit, OnDestroy } } }; - - // Set the defaults - this.comingSoonFormErrors = { - email: {} - }; - - // Set the private defaults - this._unsubscribeAll = new Subject(); } // ----------------------------------------------------------------------------------------------------- @@ -71,50 +57,5 @@ export class ComingSoonComponent implements OnInit, OnDestroy this.comingSoonForm = this._formBuilder.group({ email: ['', [Validators.required, Validators.email]] }); - - this.comingSoonForm.valueChanges - .pipe(takeUntil(this._unsubscribeAll)) - .subscribe(() => { - this.onRegisterFormValuesChanged(); - }); - } - - /** - * On destroy - */ - ngOnDestroy(): void - { - // Unsubscribe from all subscriptions - this._unsubscribeAll.next(); - this._unsubscribeAll.complete(); - } - - // ----------------------------------------------------------------------------------------------------- - // @ Public methods - // ----------------------------------------------------------------------------------------------------- - - /** - * On form values changed - */ - onRegisterFormValuesChanged(): void - { - for ( const field in this.comingSoonFormErrors ) - { - if ( !this.comingSoonFormErrors.hasOwnProperty(field) ) - { - continue; - } - - // Clear previous errors - this.comingSoonFormErrors[field] = {}; - - // Get the control - const control = this.comingSoonForm.get(field); - - if ( control && control.dirty && !control.valid ) - { - this.comingSoonFormErrors[field] = control.errors; - } - } } }