1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00
Files
browser/libs/angular/src/admin-console/validators/not-allowed-value-async.validator.ts
renovate[bot] 28de9439be [deps] Autofill: Update prettier to v3 (#7014)
* [deps] Autofill: Update prettier to v3

* prettier formatting updates

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Prusik <jprusik@classynemesis.com>
2023-11-29 16:15:20 -05:00

22 lines
628 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,
};
}
};
}