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-video-settings.component.ts | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'client/src/app/+my-account/my-account-settings/my-account-video-settings') diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts index 4588f73db..85b3a48cc 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts @@ -1,10 +1,11 @@ import { Component, Input, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { NotificationsService } from 'angular2-notifications' import { UserUpdateMe } from '../../../../../../shared' import { AuthService } from '../../../core' import { FormReactive, User, UserService } from '../../../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-video-settings', @@ -13,14 +14,11 @@ import { I18n } from '@ngx-translate/i18n-polyfill' }) export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit { @Input() user: User = null - - form: FormGroup - formErrors = {} - validationMessages = {} + @Input() userInformationLoaded: Subject constructor ( + protected formValidatorService: FormValidatorService, private authService: AuthService, - private formBuilder: FormBuilder, private notificationsService: NotificationsService, private userService: UserService, private i18n: I18n @@ -28,17 +26,18 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI super() } - buildForm () { - this.form = this.formBuilder.group({ - nsfwPolicy: [ this.user.nsfwPolicy ], - autoPlayVideo: [ this.user.autoPlayVideo ] + ngOnInit () { + this.buildForm({ + nsfwPolicy: null, + autoPlayVideo: null }) - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() + this.userInformationLoaded.subscribe(() => { + this.form.patchValue({ + nsfwPolicy: this.user.nsfwPolicy, + autoPlayVideo: this.user.autoPlayVideo === true ? 'true' : 'false' + }) + }) } updateDetails () { -- cgit v1.2.3