From a2fc73e60b3a12722df592b764161cedde3ba651 Mon Sep 17 00:00:00 2001 From: Kim Tran Date: Fri, 6 Sep 2024 12:38:29 +0200 Subject: [PATCH] feat: add searchCriteriaNotEmptyValidator (#441) * feat: add searchCriteriaNotEmptyValidator * fix: rename validator --------- Co-authored-by: kim.tran --- libs/angular-accelerator/src/index.ts | 1 + .../lib/functions/at-least-one-field-filled-validator.ts | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 libs/angular-accelerator/src/lib/functions/at-least-one-field-filled-validator.ts diff --git a/libs/angular-accelerator/src/index.ts b/libs/angular-accelerator/src/index.ts index cb16dd1f..dce3968c 100644 --- a/libs/angular-accelerator/src/index.ts +++ b/libs/angular-accelerator/src/index.ts @@ -47,6 +47,7 @@ export * from './lib/angular-accelerator-primeng.module' // functions export * from './lib/functions/flatten-object' +export * from './lib/functions/at-least-one-field-filled-validator' // utils export * from './lib/utils/async-translate-loader.utils' diff --git a/libs/angular-accelerator/src/lib/functions/at-least-one-field-filled-validator.ts b/libs/angular-accelerator/src/lib/functions/at-least-one-field-filled-validator.ts new file mode 100644 index 00000000..d029fbfc --- /dev/null +++ b/libs/angular-accelerator/src/lib/functions/at-least-one-field-filled-validator.ts @@ -0,0 +1,8 @@ +import { ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms' + +export const atLeastOneFieldFilledValidator: ValidatorFn = (form: AbstractControl): ValidationErrors | null => { + if (Object.values(form.value).every((x) => x === null || x === undefined || x === '')) { + return { allFieldsEmpty: true } + } + return null +}