• Overview
@angular/forms/signals

required

function

Binds a validator to the given path that requires the value to be non-empty. This function can only be called on any type of path. In addition to binding a validator, this function adds REQUIRED property to the field.

API

function required<TValue, TPathKind extends PathKind = PathKind.Root>(
  path: FieldPath<TValue, TPathKind>,
  config?:
    | (BaseValidatorConfig<TValue, TPathKind> & {
        emptyPredicate?: ((value: TValue) => boolean) | undefined;
        when?: NoInfer<LogicFn<TValue, boolean, TPathKind>> | undefined;
      })
    | undefined,
): void;

required

void

Binds a validator to the given path that requires the value to be non-empty. This function can only be called on any type of path. In addition to binding a validator, this function adds REQUIRED property to the field.

@parampathFieldPath<TValue, TPathKind>

Path of the field to validate

@paramconfig(BaseValidatorConfig<TValue, TPathKind> & { emptyPredicate?: ((value: TValue) => boolean) | undefined; when?: NoInfer<LogicFn<TValue, boolean, TPathKind>> | undefined; }) | undefined

Optional, allows providing any of the following options:

  • message: A user-facing message for the error.
  • error: Custom validation error(s) to be used instead of the default ValidationError.required() or a function that receives the FieldContext and returns custom validation error(s).
  • emptyPredicate: A function that receives the value, and returns true if it is considered empty. By default false, '', null, and undefined are considered empty
  • when: A function that receives the FieldContext and returns true if the field is required
@returnsvoid
Jump to details