Correction pour soumettre le formulaire

avec la touche "Enter"
This commit is contained in:
Sébastien André
2021-08-27 16:45:20 +02:00
parent cb63dc8995
commit 0745943c5b
2 changed files with 16 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
<form [formGroup]="loginForm" (ngSubmit)="onLoginSubmit()" autocomplete="off" style="padding: 10px;">
<form focusInvalidInput autocomplete="off" style="padding: 10px;"
[formGroup]="loginForm" (ngSubmit)="onLoginSubmit()">
<p>
<mat-form-field>
<mat-label>{{ 'LoginUser_Username' | translate }}</mat-label>

View File

@@ -39,7 +39,7 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
username: ['', [Validators.required, Validators.minLength(3)]],
password: ['', [Validators.required]]
},
{ updateOn: 'blur' }
{ updateOn: 'submit' }
);
// get return url from route parameters or default to '/'
@@ -54,21 +54,19 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
onLoginSubmit() {
this.submitted = true;
if (this.loginForm.invalid) {
return;
if (this.loginForm.valid) {
this.loading = true;
this.authenticationService.login(this.formCtrls.username.value, this.formCtrls.password.value)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.error = error;
this.loading = false;
}
);
}
this.loading = true;
this.authenticationService.login(this.formCtrls.username.value, this.formCtrls.password.value)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.error = error;
this.loading = false;
}
);
}
}