fix(cnsl): some saml provider issues (#7220)

Co-authored-by: Max Peintner <[email protected]>
This commit is contained in:
Miguel Cabrerizo
2024-01-15 15:10:45 +00:00
committed by GitHub
co-authored by Max Peintner
parent c7e45f7f49
commit fc34896092
4 changed files with 68 additions and 23 deletions
@@ -83,3 +83,23 @@ function i18nErr(err: ValidationErrors | null | undefined, i18nKey: string, para
};
}
}
const isFieldEmpty = (fieldName: string, g: AbstractControl) => {
const field = g.get(fieldName)?.value;
if (typeof field === 'number') {
return field && field >= 0 ? true : false;
}
if (typeof field === 'string') {
return field && field.length > 0 ? true : false;
}
return false;
};
// Reference: https://stackoverflow.com/a/56057955
export function atLeastOneIsFilled(...fields: string[]): ValidationErrors | null {
return (g: AbstractControl): ValidationErrors | null => {
return fields.some((fieldName) => isFieldEmpty(fieldName, g))
? null
: ({ atLeastOne: 'At least one field has to be provided.' } as ValidationErrors);
};
}