update form validation

This commit is contained in:
Chneemann 2024-08-02 19:15:42 +02:00
parent 355de791a0
commit fbf7c314a4
4 changed files with 41 additions and 6 deletions

View file

@ -19,7 +19,11 @@
disabled disabled
required required
/> />
<div class="error-msg"></div> <div class="error-msg">
@if (!authData.params) {
<p>Click <a routerLink="">here</a> to resend the registration email.</p>
}
</div>
<input <input
type="password" type="password"
id="password" id="password"
@ -30,6 +34,8 @@
[(ngModel)]="authData.password" [(ngModel)]="authData.password"
pattern="[^<>]*" pattern="[^<>]*"
minlength="6" minlength="6"
[class.error-border]="password.invalid && password.touched"
[disabled]="!authData.params"
required required
/> />
<div class="error-msg"> <div class="error-msg">
@ -47,6 +53,11 @@
[(ngModel)]="authData.passwordConfirm" [(ngModel)]="authData.passwordConfirm"
pattern="[^<>]*" pattern="[^<>]*"
minlength="6" minlength="6"
[class.error-border]="
authData.password !== authData.passwordConfirm &&
passwordConfirm.touched
"
[disabled]="!authData.params"
required required
/> />
<div class="error-msg"> <div class="error-msg">
@ -58,7 +69,8 @@
<app-btn-large <app-btn-large
[value]="'Get Started'" [value]="'Get Started'"
[disabled]=" [disabled]="
!isUserEmailValid(authData.mail) && authData.mail.length > 0 (!isUserEmailValid(authData.mail) && authData.mail.length > 0) ||
!authData.params
" "
></app-btn-large> ></app-btn-large>
</form> </form>

View file

@ -49,6 +49,14 @@ section {
font-size: 12px !important; font-size: 12px !important;
font-weight: 400 !important; font-weight: 400 !important;
} }
a {
color: $red;
text-decoration: underline;
cursor: pointer;
&:hover {
text-decoration: none;
}
}
} }
.register-form { .register-form {
@ -77,4 +85,7 @@ section {
background-color: rgba($white, 0.1); background-color: rgba($white, 0.1);
} }
} }
.error-border {
border: 1px solid red;
}
} }

View file

@ -1,21 +1,34 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { BtnLargeComponent } from '../../../shared/components/btn-large/btn-large.component'; import { BtnLargeComponent } from '../../../shared/components/btn-large/btn-large.component';
import { FormsModule, NgForm } from '@angular/forms'; import { FormsModule, NgForm } from '@angular/forms';
import { ActivatedRoute, RouterLink } from '@angular/router';
@Component({ @Component({
selector: 'app-register', selector: 'app-register',
standalone: true, standalone: true,
imports: [BtnLargeComponent, FormsModule], imports: [BtnLargeComponent, FormsModule, RouterLink],
templateUrl: './register.component.html', templateUrl: './register.component.html',
styleUrl: './register.component.scss', styleUrl: './register.component.scss',
}) })
export class RegisterComponent { export class RegisterComponent {
authData = { authData = {
mail: 'test@test.de', mail: '',
params: false,
password: '', password: '',
passwordConfirm: '', passwordConfirm: '',
}; };
constructor(private route: ActivatedRoute) {}
ngOnInit(): void {
this.route.queryParams.subscribe((params) => {
this.authData.mail = params['mail'] || '';
this.authData.mail
? (this.authData.params = true)
: (this.authData.params = false);
});
}
isUserEmailValid(emailValue: string) { isUserEmailValid(emailValue: string) {
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(emailValue); return emailRegex.test(emailValue);

View file

@ -2,8 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { HeaderComponent } from './header/header.component'; import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component'; import { FooterComponent } from './footer/footer.component';
import { AuthComponent } from '../auth/auth.component'; import { AuthComponent } from '../auth/auth.component';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { filter } from 'rxjs/operators';
import { RegisterComponent } from '../auth/register/register.component'; import { RegisterComponent } from '../auth/register/register.component';
@Component({ @Component({