mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 19:23:52 +00:00
22 lines
627 B
TypeScript
22 lines
627 B
TypeScript
import { AbstractControl, AsyncValidatorFn, ValidationErrors } from "@angular/forms";
|
|
|
|
export function notAllowedValueAsync(
|
|
valueGetter: () => Promise<string>,
|
|
caseInsensitive = false
|
|
): AsyncValidatorFn {
|
|
return async (control: AbstractControl): Promise<ValidationErrors | null> => {
|
|
let notAllowedValue = await valueGetter();
|
|
let controlValue = control.value;
|
|
if (caseInsensitive) {
|
|
notAllowedValue = notAllowedValue.toLowerCase();
|
|
controlValue = controlValue.toLowerCase();
|
|
}
|
|
|
|
if (controlValue === notAllowedValue) {
|
|
return {
|
|
notAllowedValue: true,
|
|
};
|
|
}
|
|
};
|
|
}
|