Skip to content

Commit

Permalink
Dev: Angular update to v 10.2 (fixed type problem: microsoft/TypeScri…
Browse files Browse the repository at this point in the history
  • Loading branch information
pergalsk committed Jun 18, 2022
1 parent bf0f2b5 commit ed5202f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/app/services/validators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
}
Expand Down

0 comments on commit ed5202f

Please sign in to comment.