From d18d64787b3ea174f7dc2740c8c8c9555625047e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Jun 2018 10:58:45 +0200 Subject: Form validators refractoring --- .../app/reset-password/reset-password.component.ts | 31 +++++----------------- 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'client/src/app/reset-password/reset-password.component.ts') diff --git a/client/src/app/reset-password/reset-password.component.ts b/client/src/app/reset-password/reset-password.component.ts index c8bd368c1..58e086f45 100644 --- a/client/src/app/reset-password/reset-password.component.ts +++ b/client/src/app/reset-password/reset-password.component.ts @@ -1,11 +1,12 @@ import { Component, OnInit } from '@angular/core' -import { FormBuilder, FormGroup, Validators } from '@angular/forms' import { ActivatedRoute, Router } from '@angular/router' import { USER_PASSWORD, UserService } from '@app/shared' import { NotificationsService } from 'angular2-notifications' import { AuthService } from '../core' import { FormReactive } from '../shared' import { I18n } from '@ngx-translate/i18n-polyfill' +import { RESET_PASSWORD_CONFIRM } from '@app/shared/forms/form-validators/reset-password' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-login', @@ -14,26 +15,14 @@ import { I18n } from '@ngx-translate/i18n-polyfill' }) export class ResetPasswordComponent extends FormReactive implements OnInit { - form: FormGroup - formErrors = { - 'password': '', - 'password-confirm': '' - } - validationMessages = { - 'password': USER_PASSWORD.MESSAGES, - 'password-confirm': { - 'required': 'Confirmation of the password is required.' - } - } - private userId: number private verificationString: string constructor ( + protected formValidatorService: FormValidatorService, private authService: AuthService, private userService: UserService, private notificationsService: NotificationsService, - private formBuilder: FormBuilder, private router: Router, private route: ActivatedRoute, private i18n: I18n @@ -41,17 +30,11 @@ export class ResetPasswordComponent extends FormReactive implements OnInit { super() } - buildForm () { - this.form = this.formBuilder.group({ - password: [ '', USER_PASSWORD.VALIDATORS ], - 'password-confirm': [ '', Validators.required ] - }) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - ngOnInit () { - this.buildForm() + this.buildForm({ + password: USER_PASSWORD, + 'password-confirm': RESET_PASSWORD_CONFIRM + }) this.userId = this.route.snapshot.queryParams['userId'] this.verificationString = this.route.snapshot.queryParams['verificationString'] -- cgit v1.2.3