From bf0043d15fe9e5326a1f0baceebd290a5e104f8a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 25 Dec 2022 22:35:36 +0100 Subject: [PATCH] feat: Added validation for the "Pick Name"-form --- src/app/user/user.component.html | 14 +++++++++++--- src/app/user/user.component.ts | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/user/user.component.html b/src/app/user/user.component.html index 6108608d..b640cfd6 100644 --- a/src/app/user/user.component.html +++ b/src/app/user/user.component.html @@ -6,10 +6,18 @@
- + +
+
+ +
+ Name is required. +
- + -

Value: {{ name.value }}

+

Value: {{ usernameForm.value }}

+

Form Status: {{ usernameForm.status }}

diff --git a/src/app/user/user.component.ts b/src/app/user/user.component.ts index 7e3caeb4..0ec30268 100644 --- a/src/app/user/user.component.ts +++ b/src/app/user/user.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; import { FormControl } from '@angular/forms'; +import { Validators } from '@angular/forms'; import { Router } from "@angular/router"; import { UserService } from "../user.service"; @@ -10,10 +11,10 @@ import { UserService } from "../user.service"; }) export class UserComponent { - name = new FormControl(''); + usernameForm = new FormControl('', Validators.required); updateName(): void { - var input = this.name.getRawValue(); + var input = this.usernameForm.getRawValue(); if (input !== null) { this.userService.setUser(input); this.router.navigate(['chatrooms']) -- 2.20.1