From d18d64787b3ea174f7dc2740c8c8c9555625047e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Jun 2018 10:58:45 +0200 Subject: Form validators refractoring --- .../my-account-profile.component.ts | 35 +++++++++------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'client/src/app/+my-account/my-account-settings/my-account-profile') diff --git a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts index 35843ecd9..1fe337da0 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts @@ -1,9 +1,10 @@ import { Component, Input, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { NotificationsService } from 'angular2-notifications' import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared' import { User } from '@app/shared' import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { Subject } from 'rxjs/Subject' @Component({ selector: 'my-account-profile', @@ -12,21 +13,12 @@ import { I18n } from '@ngx-translate/i18n-polyfill' }) export class MyAccountProfileComponent extends FormReactive implements OnInit { @Input() user: User = null + @Input() userInformationLoaded: Subject error: string = null - form: FormGroup - formErrors = { - 'display-name': '', - 'description': '' - } - validationMessages = { - 'display-name': USER_DISPLAY_NAME.MESSAGES, - 'description': USER_DESCRIPTION.MESSAGES - } - constructor ( - private formBuilder: FormBuilder, + protected formValidatorService: FormValidatorService, private notificationsService: NotificationsService, private userService: UserService, private i18n: I18n @@ -34,17 +26,18 @@ export class MyAccountProfileComponent extends FormReactive implements OnInit { super() } - buildForm () { - this.form = this.formBuilder.group({ - 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ], - 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ] + ngOnInit () { + this.buildForm({ + 'display-name': USER_DISPLAY_NAME, + description: USER_DESCRIPTION }) - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() + this.userInformationLoaded.subscribe(() => { + this.form.patchValue({ + 'display-name': this.user.account.displayName, + description: this.user.account.description + }) + }) } updateMyProfile () { -- cgit v1.2.3