mirror of
https://github.com/bitwarden/jslib
synced 2026-01-02 16:43:39 +00:00
Merge branch 'master' of https://github.com/bitwarden/jslib into feature/additional-item-types-scaffold
This commit is contained in:
21
angular/src/validators/notAllowedValueAsync.validator.ts
Normal file
21
angular/src/validators/notAllowedValueAsync.validator.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user