Options
All
  • Public
  • Public/Protected
  • All
Menu

An abstract class that defines the base pattern for a data field within a data schema.

abstract
property

{string} name The name of this data field within the schema that contains it

property

{boolean} required=false Is this field required to be populated?

property

{boolean} nullable=false Can this field have null values?

property

{Function|*} initial The initial value of a field, or a function which assigns that initial value.

property

{Function} validate A data validation function which accepts one argument with the current value.

property

{boolean} [readonly=false] Should the prepared value of the field be read-only, preventing it from being changed unless a change to the _source data is applied.

property

{string} label A localizable label displayed on forms which render this field.

property

{string} hint Localizable help text displayed on forms which render this field.

property

{string} validationError A custom validation error string. When displayed will be prepended with the document name, field name, and candidate value.

Hierarchy

Index

Constructors

Properties

The initially provided options which configure the data field

name: any

The field name of this DataField instance. This is assigned by SchemaField#initialize.

internal
parent: any

A reference to the parent schema to which this DataField belongs. This is assigned by SchemaField#initialize.

internal

Accessors

  • get fieldPath(): string
  • A dot-separated string representation of the field path within the parent schema.

    Returns string

Methods

  • apply(fn: string | Function, value: any, options?: any): any
  • Apply a function to this DataField which propagates through recursively to any contained data schema.

    Parameters

    • fn: string | Function

      The function to apply

    • value: any

      The current value of this field

    • options: any = {}

    Returns any

    The results object

  • clean(value: any, options: { partial: boolean; source: any }): any
  • Coerce source data to ensure that it conforms to the correct data type for the field. Data coercion operations should be simple and synchronous as these are applied whenever a DataModel is constructed. For one-off cleaning of user-provided input the sanitize method should be used.

    Parameters

    • value: any

      The initial value

    • options: { partial: boolean; source: any }
      • partial: boolean
      • source: any

    Returns any

    The cast value

  • getInitialValue(data: any): any
  • Attempt to retrieve a valid initial value for the DataField.

    throws

    An error if there is no valid initial value defined

    Parameters

    • data: any

      The source data object for which an initial value is required

    Returns any

    A valid initial value

  • Validate a candidate input for this field, ensuring it meets the field requirements. A validation failure can be provided as a raised Error (with a string message) or by returning false. A validator which returns true denotes that the result is certainly valid and further validations are unnecessary.

    Parameters

    • value: any

      The initial value

    • options: any = {}

    Returns ModelValidationError

    Returns a ModelValidationError if a validation failure occurred

  • initialize(value: any, model: any): any
  • Initialize the original source data into a mutable copy for the DataModel instance.

    Parameters

    • value: any

      The source value of the field

    • model: any

      The DataModel instance that this field belongs to

    Returns any

    An initialized copy of the source data

  • toObject(value: any): any
  • Export the current value of the field into a serializable object.

    Parameters

    • value: any

      The initialized value of the field

    Returns any

    An exported representation of the field

  • _cleanType(value: any, options: any): any
  • Apply any cleaning logic specific to this DataField type.

    Parameters

    • value: any

      The appropriately coerced value.

    • options: any

    Returns any

    The cleaned value.

  • _cast(value: any): any
  • Cast a non-default value to ensure it is the correct type for the field

    Parameters

    • value: any

      The provided non-default value

    Returns any

    The standardized value

  • _validateSpecial(value: any): boolean | void
  • Special validation rules which supersede regular field validation. This validator screens for certain values which are otherwise incompatible with this field like null or undefined.

    throws

    May throw a specific error if the value is not valid

    Parameters

    • value: any

      The candidate value

    Returns boolean | void

    A boolean to indicate with certainty whether the value is valid. Otherwise, return void.

  • _validateType(value: any, options?: any): boolean | void
  • A default type-specific validator that can be overridden by child classes

    throws

    May throw a specific error if the value is not valid

    Parameters

    • value: any

      The candidate value

    • options: any = {}

    Returns boolean | void

    A boolean to indicate with certainty whether the value is valid. Otherwise, return void.