From ed5202fde570cf05c581d41033e6c6398217113f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20G=C3=A1l?= Date: Sat, 18 Jun 2022 13:45:00 +0200 Subject: [PATCH] Dev: Angular update to v 10.2 (fixed type problem: https://github.com/microsoft/TypeScript/issues/36390) --- src/app/services/validators.service.ts | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app/services/validators.service.ts b/src/app/services/validators.service.ts index 0e8727b..266f010 100644 --- a/src/app/services/validators.service.ts +++ b/src/app/services/validators.service.ts @@ -71,20 +71,23 @@ export class ValidatorsService { groupRequiredValidator(controlNamesSet: string[] | string[][], message?: string): ValidatorFn { return (control: FormGroup): ValidationErrors | null => { // in every control names set has to be at least one control with non-empty string value - const hasValue: boolean = controlNamesSet.every((controlNames: string[] | string) => { - if (typeof controlNames === 'string') { - controlNames = [controlNames]; + // (fixed problem with 'every' https://github.com/microsoft/TypeScript/issues/36390) + const hasValue: boolean = (controlNamesSet as any).every( + (controlNames: string[] | string) => { + if (typeof controlNames === 'string') { + controlNames = [controlNames]; + } + if (Array.isArray(controlNames)) { + return controlNames.some((controlName: string) => { + const ctrl: AbstractControl = control.get(controlName); + // this works for different types of form value + return ctrl && !this.utilsService.isEmpty(ctrl.value); + }); + } else { + return true; // if something other than string or array don't mark as error + } } - if (Array.isArray(controlNames)) { - return controlNames.some((controlName: string) => { - const ctrl: AbstractControl = control.get(controlName); - // this works for different types of form value - return ctrl && !this.utilsService.isEmpty(ctrl.value); - }); - } else { - return true; // if something other than string or array don't mark as error - } - }); + ); return hasValue ? null : { groupRequired: message ? { message } : true }; }; }