Interface

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 fnfunctionName 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 BaseValidatorConfig

Properties

NameTypeDescription
type "custom"Validator type identifier
functionName ?string | undefinedName of registered validator function (function-based pattern)
fn ?CustomValidator | undefined

Inline custom validator (code-only authoring). Mutually exclusive with functionName. NOT JSON-serializable.

params ?Record<string, unknown> | undefinedOptional parameters to pass to validator function
expression ?string | undefinedJavaScript expression to evaluate (expression-based pattern)
kind ?string | undefinedError 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