Files
dspace-angular/src/app/register-page/create-profile/confirmed.validator.ts
2020-05-28 09:41:16 +02:00

20 lines
665 B
TypeScript

import { FormGroup } from '@angular/forms';
/**
* Validator used to confirm that the password and confirmed password value are the same
*/
export function ConfirmedValidator(controlName: string, matchingControlName: string) {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (matchingControl.errors && !matchingControl.errors.confirmedValidator) {
return;
}
if (control.value !== matchingControl.value) {
matchingControl.setErrors({confirmedValidator: true});
} else {
matchingControl.setErrors(null);
}
};
}