Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Class ArrayField<ElementType>

    A subclass of foundry.data.fields.DataField which deals with array-typed data.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    element: ElementType

    The data type of each element in this array

    name: string | undefined

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

    The initially provided options which configure the data field

    parent: any

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

    persisted: boolean = true

    Is a value of this field written to source data? A Non-persisted value is initialized (with its initial value), and ActiveEffects can use the field for change application.

    hierarchical: boolean = false

    Whether this field defines part of a Document/Embedded Document hierarchy.

    recursive: boolean = true

    Accessors

    • get fieldPath(): string

      A dot-separated string representation of the field path within the parent schema.

      Returns string

    • get _defaults(): DataFieldOptions & {
          empty: boolean;
          exact: undefined;
          max: number;
          min: number;
          nullable: boolean;
          required: boolean;
      }

      Default parameters for this field type

      Returns DataFieldOptions & {
          empty: boolean;
          exact: undefined;
          max: number;
          min: number;
          nullable: boolean;
          required: boolean;
      }

    • get hasFormSupport(): boolean

      Does this form field class have defined form support?

      Returns boolean

    Methods

    • Parameters

      • value: any
      • delta: any
      • model: any
      • change: any

      Returns any

    • Parameters

      • value: unknown[]
      • delta: unknown[]
      • model: any
      • change: any

      Returns unknown[]

    • Parameters

      • value: any

      Returns any[]

    • Parameters

      • raw: any
      • replacementData: any

      Returns any[]

    • When cleaning an ArrayField we must force {partial: false} since arrays are always fully replaced. We take care to preserve the provided array reference, cleaning its elements rather than replacing the array.

      Parameters

      • value: any
      • options: any
      • _state: any

      Returns any

    • Parameters

      • parts: any
      • __namedParameters: {} = {}

      Returns any

    • Commit array field changes by replacing array contents while preserving the array reference itself.

      Parameters

      • source: any
      • key: any
      • value: any
      • _diff: any
      • _options: any

      Returns void

    • Parameters

      • key: any
      • value: any
      • options: any
      • state: any

      Returns void

    • Parameters

      • changes: any
      • options: any

      Returns void

    • Parameters

      • value: any
      • options: any

      Returns void

    • Parameters

      • fn: any
      • value: any[] = []
      • options: {} = {}

      Returns any[]

    • Apply an ActiveEffectChange to this field.

      Type Parameters

      • T

      Parameters

      • value: T

        The field's current value.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The change to apply.

      • options: { replacementData?: Record<string, unknown> } = {}

        Additional options to configure the change application.

        • OptionalreplacementData?: Record<string, unknown>

          Data used to resolve "@" expressions.

      Returns T

      The updated value.

    • Preprocess and clean source data to ensure that it conforms to the correct data type for this field and is ready to be used by data model construction or update operations. Data cleaning is synchronous and automatically applied as the first step of construction and update operations.

      Parameters

      Returns any

      The cleaned value

    • Parameters

      • value: any
      • model: any
      • options: {} = {}

      Returns any

    • Render this DataField as a standardized form-group element.

      Parameters

      • groupConfig: FormGroupConfig = {}

        Configuration options passed to the wrapping form-group

      • inputConfig: FormInputConfig = {}

        Input element configuration options passed to DataField#toInput

      Returns HTMLDivElement

      The rendered form group element

    • Render this DataField as an HTML element.

      Parameters

      Returns HTMLElement | HTMLCollection | HTMLElement[]

      A rendered HTMLElement for the field

      An Error if this DataField subclass does not support input rendering

    • Validate candidate input for this field, ensuring it meets the field requirements.

      This public method validates recursively, testing both the immediate value of this field as well as the validity of any child values for fields with hierarchical data types.

      Parameters

      • value: any

        The candidate value to validate

      • Optionaloptions: DataFieldValidationOptions = {}

        Options which affect validation behavior

      Returns void | DataModelValidationFailure

      A failure that occurred if validation is non-strict. The failure may have been resolved by fallback or dropping invalid elements.

      A failure error type including details of the failure if validation is performed strictly.

    • Iterate over validation functions applied to this field. Validation happens in a depth-first way, for example consider an outerSchema with an innerField:

      Parameters

      Returns Generator<DataFieldValidator, void, unknown>

      outerSchema
      _validateSpecial
      _validateType
      _validateRecursive
      outerSchema.options.validate
      innerField
      _validateSpecial
      _validateType
      innerField.options.validate
      _validateModel
      _validateModel
    • Protected

      Apply a custom change to this field.

      Parameters

      • value: any

        The field's current value.

      • delta: any

        The change delta.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The original change data.

      Returns any

      The updated value.

    • Protected

      Apply a "downgrade" change to this field.

      Parameters

      • value: any

        The field's current value.

      • delta: any

        The change delta.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The original change data.

      Returns any

      The updated value.

    • Protected

      Apply a "multiply" change to this field.

      Parameters

      • value: any

        The field's current value.

      • delta: any

        The change delta.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The original change data.

      Returns any

      The updated value.

    • Protected

      Apply an "override" change to this field.

      Parameters

      • value: any

        The field's current value.

      • delta: any

        The change delta.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The original change data.

      Returns any

      The updated value.

    • Protected

      Apply an "upgrade" change to this field.

      Parameters

      • value: any

        The field's current value.

      • delta: any

        The change delta.

      • model: DataModel

        The model instance.

      • change: EffectChangeData

        The original change data.

      Returns any

      The updated value.

    • Protected

      Recursively replace data references in a string change value.

      Parameters

      • raw: string
      • data: Record<string, unknown>

        An object providing replacements

      • Optionaloptions: { strict?: boolean } = {}

        Additional options to configure the data replacement

        • Optionalstrict?: boolean

          Throw an Error if data replacement fails

      Returns string

      The expression with data references resolved

    • Protected

      Render this DataField as an HTML element. Subclasses should implement this method rather than the public toInput method which wraps it.

      Parameters

      Returns HTMLElement | HTMLCollection | HTMLElement[]

      A rendered HTMLElement for the field

      An Error if this DataField subclass does not support input rendering

    • Protected

      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.

      Parameters

      • value: any

        The candidate value

      Returns boolean | void

      A boolean to indicate with certainty whether the value is valid

      An error with a specific reason the value is invalid

    • Internal

      Parameters

      • field: any
      • value: any
      • index: any
      • parentFailure: any
      • fieldFailure: any
      • options: any

      Returns void

    • Protected

      Validate the contained element type of the ArrayField

      Parameters

      • element: any

        The type of Array element

      Returns ElementType

      The validated element type

      An error if the element is not a valid type