mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
Move to libs
This commit is contained in:
9
libs/angular/src/validators/dirty.validator.ts
Normal file
9
libs/angular/src/validators/dirty.validator.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AbstractControl, ValidationErrors, Validators } from "@angular/forms";
|
||||
|
||||
/**
|
||||
* Runs Validators.required on a field only if it's dirty. This prevents error messages from being displayed
|
||||
* to the user prematurely.
|
||||
*/
|
||||
export function dirtyRequired(control: AbstractControl): ValidationErrors | null {
|
||||
return control.dirty ? Validators.required(control) : null;
|
||||
}
|
||||
@@ -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