chore: Fix validation
This commit is contained in:
parent
b8f66bce0f
commit
b6278dfe2f
2 changed files with 13 additions and 5 deletions
|
@ -6,6 +6,7 @@ import {
|
|||
Validators,
|
||||
} from '@angular/forms';
|
||||
import AuthService from '../../../service/auth.service';
|
||||
import CustomValidators from '../../../service/custom.validators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-register',
|
||||
|
@ -22,10 +23,15 @@ export default class RegisterComponent {
|
|||
confirmEmail: ['', [Validators.required, Validators.email]],
|
||||
});
|
||||
|
||||
passwordGroup: FormGroup = this.fb.group({
|
||||
password: ['', Validators.required],
|
||||
confirmPassword: ['', Validators.required],
|
||||
});
|
||||
passwordGroup: FormGroup = this.fb.group(
|
||||
{
|
||||
password: ['', [Validators.required]],
|
||||
confirmPassword: ['', Validators.required],
|
||||
},
|
||||
{
|
||||
validators: CustomValidators.password(),
|
||||
},
|
||||
);
|
||||
|
||||
addressGroup: FormGroup = this.fb.group({
|
||||
city: ['', Validators.required],
|
||||
|
@ -45,6 +51,7 @@ export default class RegisterComponent {
|
|||
|
||||
submit() {
|
||||
if (!this.form.valid) {
|
||||
console.log(this.form.controls['password'].errors);
|
||||
console.log(this.form.value);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,12 @@ export default class CustomValidators {
|
|||
|
||||
public static password(): ValidatorFn {
|
||||
return (passwordGroup: AbstractControl) => {
|
||||
console.log(passwordGroup);
|
||||
if (
|
||||
passwordGroup.get('password')?.value !==
|
||||
passwordGroup.get('confirmPassword')
|
||||
) {
|
||||
return { emailMismatch: true };
|
||||
return { passwordMismatch: true };
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue