CustomValidatorConfig
@ng-forge/dynamic-forms
Custom validator configuration using Angular's public FieldContext API. Returns ValidationError | ValidationError[] | null synchronously.
Three authoring forms (mutually exclusive at runtime, not enforced by TypeScript):
1. Registered function: { type: 'custom', functionName: 'myValidator' }
2. Inline function (code-only): { type: 'custom', fn: (ctx) => ... }
3. Expression-based: { type: 'custom', expression: 'fieldValue === formValue.password', kind: 'passwordMismatch' }
Unlike AsyncValidatorConfig and FunctionHttpValidatorConfig (strict fn ↔
functionName XOR via discriminated unions), this surface keeps a permissive
interface — the historical expression-vs-functionName split was already
runtime-checked, so adding fn follows the same precedent. The runtime
resolver picks one source and warns if fn and functionName are both set;
inline fn wins.
fn is NOT JSON-serializable — for code-only configs. For configs loaded from
JSON / OpenAPI / databases, prefer functionName to reference a function
registered in customFnConfig.validators.
Signature
interface CustomValidatorConfig
extends BaseValidatorConfigProperties
| Name | Type | Description |
|---|---|---|
type | "custom" | Validator type identifier |
functionName ? | string | undefined | Name of registered validator function (function-based pattern) |
fn ? | CustomValidator | undefined | Inline custom validator (code-only authoring).
Mutually exclusive with |
params ? | Record<string, unknown> | undefined | Optional parameters to pass to validator function |
expression ? | string | undefined | JavaScript expression to evaluate (expression-based pattern) |
kind ? | string | undefined | Error kind for expression-based validators - links to validationMessages |
errorParams ? | Record<string, string> | undefined | Parameters to include in error object for message interpolation (expression-based pattern) Map of parameter names to expressions that will be evaluated in the same context as the validation expression |
packages/dynamic-forms/src/lib/models/validation/validator-config.ts:48