Début de fix pour avoir la navigation au clavier dans le
formulaire de login
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
<p>
|
<p>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Username</mat-label>
|
<mat-label>Username</mat-label>
|
||||||
<input matInput formControlName="username" [ngClass]="{ 'is-invalid': submitted && formCtrls.username.errors }"
|
<input matInput #username="matInput" formControlName="username"
|
||||||
tabindex="0">
|
[ngClass]="{ 'is-invalid': submitted && formCtrls.username.errors }">
|
||||||
<mat-error *ngIf="formCtrls.username.hasError('required')">
|
<mat-error *ngIf="formCtrls.username.hasError('required')">
|
||||||
Username is required
|
Username is required
|
||||||
</mat-error>
|
</mat-error>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Password</mat-label>
|
<mat-label>Password</mat-label>
|
||||||
<input type="password" matInput formControlName="password"
|
<input type="password" matInput formControlName="password"
|
||||||
[ngClass]="{ 'is-invalid': submitted && formCtrls.password.errors }" tabindex="1">
|
[ngClass]="{ 'is-invalid': submitted && formCtrls.password.errors }">
|
||||||
<mat-error *ngIf="formCtrls.password.hasError('required')">
|
<mat-error *ngIf="formCtrls.password.hasError('required')">
|
||||||
Password is required
|
Password is required
|
||||||
</mat-error>
|
</mat-error>
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
|
||||||
import { Router, ActivatedRoute } from "@angular/router";
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { MatInput } from '@angular/material/input';
|
||||||
|
|
||||||
import { first } from "rxjs/operators";
|
import { first } from 'rxjs/operators';
|
||||||
|
|
||||||
import { AuthenticationService } from "../../services/authentication.service";
|
import { AuthenticationService } from '../../services/authentication.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-login-user",
|
selector: 'app-login-user',
|
||||||
templateUrl: "./login-user.component.html",
|
templateUrl: './login-user.component.html',
|
||||||
styleUrls: ["./login-user.component.css"]
|
styleUrls: ['./login-user.component.css']
|
||||||
})
|
})
|
||||||
export class LoginUserComponent implements OnInit {
|
export class LoginUserComponent implements OnInit, AfterViewInit {
|
||||||
loginForm: FormGroup;
|
loginForm: FormGroup;
|
||||||
loading = false;
|
loading = false;
|
||||||
submitted = false;
|
submitted = false;
|
||||||
returnUrl: string;
|
returnUrl: string;
|
||||||
error = "";
|
error = '';
|
||||||
|
@ViewChild('username') userNameInput: MatInput;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
@@ -26,26 +28,31 @@ export class LoginUserComponent implements OnInit {
|
|||||||
) {
|
) {
|
||||||
// redirect to home if already logged in
|
// redirect to home if already logged in
|
||||||
if (this.authenticationService.currentUserValue) {
|
if (this.authenticationService.currentUserValue) {
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(['/']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
this.userNameInput.focus();
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.loginForm = this.formBuilder.group(
|
this.loginForm = this.formBuilder.group(
|
||||||
{
|
{
|
||||||
username: ["", [Validators.required, Validators.minLength(3)]],
|
username: ['', [Validators.required, Validators.minLength(3)]],
|
||||||
password: [
|
password: [
|
||||||
"",
|
'',
|
||||||
[
|
[
|
||||||
Validators.required /*, Validators.pattern("^[A-Za-z0-9_-]{8,15}$")*/
|
Validators.required /*, Validators.pattern("^[A-Za-z0-9_-]{8,15}$")*/
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ updateOn: "blur" }
|
{ updateOn: 'blur' }
|
||||||
);
|
);
|
||||||
|
|
||||||
// get return url from route parameters or default to '/'
|
// get return url from route parameters or default to '/'
|
||||||
this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/";
|
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get formCtrls() {
|
get formCtrls() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
width: 100vw;
|
/*width: 100vw;*/
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user