Skip to content

Commit 09778e8

Browse files
authored
Merge pull request DSpace#5666 from DSpace/backport-4999-to-dspace-8_x
[Port dspace-8_x] fix: use built-in Angular email validator for eperson form
2 parents d4455b7 + af082fe commit 09778e8

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,28 @@ describe('EPersonFormComponent', () => {
316316
});
317317
});
318318

319+
describe('with uppercased email specified', () => {
320+
beforeEach(() => {
321+
component.formGroup.controls.firstName.setValue('test');
322+
component.formGroup.controls.lastName.setValue('test');
323+
component.formGroup.controls.email.setValue('TEST@test.com');
324+
fixture.detectChanges();
325+
});
326+
327+
it('passes validation check', () => {
328+
expect(component.formGroup.controls.email.valid).toBeTrue();
329+
expect(component.formGroup.controls.email.errors).toBeNull();
330+
});
331+
});
319332

320333
describe('after inserting email wrong should show pattern validation error', () => {
321334
beforeEach(() => {
322-
component.formGroup.controls.email.setValue('test@test');
335+
component.formGroup.controls.email.setValue('test');
323336
fixture.detectChanges();
324337
});
325338
it('email should not be valid because the email pattern', () => {
326339
expect(component.formGroup.controls.email.valid).toBeFalse();
327-
expect(component.formGroup.controls.email.errors.pattern).toBeTruthy();
340+
expect(component.formGroup.controls.email.errors.email).toBeTruthy();
328341
});
329342
});
330343

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
307307
name: 'email',
308308
validators: {
309309
required: null,
310-
pattern: '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$',
310+
email: null,
311311
},
312312
required: true,
313313
errorMessages: {
314314
emailTaken: 'error.validation.emailTaken',
315-
pattern: 'error.validation.NotValidEmail',
315+
email: 'error.validation.NotValidEmail',
316316
},
317317
hint: this.translateService.instant(`${this.messagePrefix}.emailHint`),
318318
});

0 commit comments

Comments
 (0)