Skip to content
Snippets Groups Projects
Commit b9d3ea54 authored by Lukas Mauß's avatar Lukas Mauß Committed by Tom Käsler
Browse files

Fix Validation for input field

parent 7c62d422
1 merge request!141Resolve "Session ID input field enhancement"
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
placeholder="Session-Id" [formControl]="roomFormControl" [errorStateMatcher]="matcher"/> placeholder="Session-Id" [formControl]="roomFormControl" [errorStateMatcher]="matcher"/>
<mat-hint align="end">{{ roomId.value.length - (roomId.value.split(' ').length -1) }} / 8</mat-hint> <mat-hint align="end">{{ roomId.value.length - (roomId.value.split(' ').length -1) }} / 8</mat-hint>
<mat-error *ngIf="roomFormControl.hasError('required')">{{ 'home-page.please-enter' | translate}}</mat-error> <mat-error *ngIf="roomFormControl.hasError('required')">{{ 'home-page.please-enter' | translate}}</mat-error>
<mat-error *ngIf="roomFormControl.hasError('minlength')">{{ 'home-page.exactly-8' | translate}}</mat-error> <mat-error *ngIf="roomFormControl.hasError('pattern')">{{ 'home-page.only-numbers' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
<button mat-fab color="accent" type="submit"> <button mat-fab color="accent" type="submit">
<mat-icon>input</mat-icon> <mat-icon>input</mat-icon>
......
...@@ -30,7 +30,7 @@ export class RoomJoinComponent implements OnInit { ...@@ -30,7 +30,7 @@ export class RoomJoinComponent implements OnInit {
demoId = '95680586'; demoId = '95680586';
user: User; user: User;
roomFormControl = new FormControl('', [Validators.required, Validators.minLength(9), Validators.maxLength(9)]); roomFormControl = new FormControl('', [Validators.required, Validators.pattern('[0-9 ]*')]);
matcher = new RegisterErrorStateMatcher(); matcher = new RegisterErrorStateMatcher();
...@@ -46,7 +46,16 @@ export class RoomJoinComponent implements OnInit { ...@@ -46,7 +46,16 @@ export class RoomJoinComponent implements OnInit {
} }
getRoom(id: string): void { getRoom(id: string): void {
this.roomService.getRoomByShortId(id.replace(/\s/g, "")) if (id.length -1 < 8) {
this.translateService.get('home-page.exactly-8').subscribe(message => {
this.notificationService.show(message);
});
} else if (this.roomFormControl.hasError('pattern')) {
this.translateService.get('home-page.only-numbers').subscribe(message => {
this.notificationService.show(message);
});
} else {
this.roomService.getRoomByShortId(id.replace(/\s/g, ""))
.subscribe(room => { .subscribe(room => {
this.room = room; this.room = room;
if (!room) { if (!room) {
...@@ -65,6 +74,8 @@ export class RoomJoinComponent implements OnInit { ...@@ -65,6 +74,8 @@ export class RoomJoinComponent implements OnInit {
} }
} }
}); });
}
} }
joinRoom(id: string): void { joinRoom(id: string): void {
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
"create-session": "Session erstellen", "create-session": "Session erstellen",
"no-empty-name": "Bitte geben Sie einen Namen ein.", "no-empty-name": "Bitte geben Sie einen Namen ein.",
"created-1": "Session '", "created-1": "Session '",
"created-2": "' erfolgreich erstellt." "created-2": "' erfolgreich erstellt.",
"only-numbers": "Eine Session-Id besteht aus Nummern."
}, },
"login": { "login": {
"email": "E-Mail", "email": "E-Mail",
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
"create-session": "Create session", "create-session": "Create session",
"no-empty-name": "Please enter a name.", "no-empty-name": "Please enter a name.",
"created-1": "Session '", "created-1": "Session '",
"created-2": "' successfully created." "created-2": "' successfully created.",
"only-numbers": "A session-id only contains numbers."
}, },
"login": { "login": {
"email": "E-Mail", "email": "E-Mail",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment