Skip to content

Commit

Permalink
#790 improve email validation
Browse files Browse the repository at this point in the history
unique-mail validator
- filter empty strings
- update added mails every time form changes

added general email validation
  • Loading branch information
janikEndtner committed Apr 12, 2024
1 parent e04fea1 commit b081bfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UserService } from '../../services/user.service';
import { DialogRef } from '@angular/cdk/dialog';
import { NewUserForm } from '../../shared/types/model/NewUserForm';
import { UniqueEmailValidator } from '../new-user/unique-mail.validator';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
selector: 'app-invite-user-dialog',
Expand All @@ -22,6 +23,9 @@ export class InviteUserDialogComponent {
private readonly uniqueMailValidator: UniqueEmailValidator,
) {
this.form = this.formBuilder.array([this.createUserFormGroup()]);
this.form.valueChanges
.pipe(takeUntilDestroyed())
.subscribe(() => this.uniqueMailValidator.setAddedMails(this.extractAddedMails()));
}

registerUsers() {
Expand All @@ -45,13 +49,13 @@ export class InviteUserDialogComponent {
}

private createUserFormGroup() {
this.uniqueMailValidator.setAddedMails(this.extractAddedMails());
return this.formBuilder.group({
firstname: this.formBuilder.control('', [Validators.required, Validators.minLength(1)]),
lastname: this.formBuilder.control('', [Validators.required, Validators.minLength(1)]),
email: this.formBuilder.control('', [
Validators.required,
Validators.minLength(1),
Validators.email,
this.uniqueMailValidator.validate.bind(this.uniqueMailValidator),
]),
});
Expand All @@ -61,6 +65,8 @@ export class InviteUserDialogComponent {
if (!this.form) {
return [];
}
return this.extractFormValue().map((u) => u.email);
return this.extractFormValue()
.map((u) => u.email)
.filter((mail) => !!mail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<span>Angabe benötigt</span>
} @else if (email.errors?.["notUniqueMail"]) {
<span>E-Mail existiert bereits</span>
} @else if (email.errors?.["email"]) {
} @else if (email.errors?.["email"] && triedToSubmit) {
<span>E-Mail ungültig</span>
}
</mat-error>
Expand Down

0 comments on commit b081bfe

Please sign in to comment.