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

    A special foundry.data.fields.StringField which records a standardized CSS color string.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    blank: boolean

    Is the string allowed to be blank (empty)?

    choices: object | Function | string[] = ...

    An array of values or an object of values/labels which represent allowed choices for the field. A function may be provided which dynamically returns the array of choices.

    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.

    textSearch: boolean = ...

    Is this string field a target for text search?

    trim: boolean = ...

    Should any provided string be trimmed as part of cleaning?

    hierarchical: boolean = false

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

    recursive: boolean = false

    Does this field type contain other fields in a recursive structure? Examples of recursive fields are SchemaField, ArrayField, or TypeDataField Examples of non-recursive fields are StringField, NumberField, or ObjectField

    Accessors

    • get fieldPath(): string

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

      Returns string

    • get _defaults(): DataFieldOptions & {
          blank: boolean;
          choices: undefined;
          textSearch: boolean;
          trim: boolean;
      } & { blank: boolean; initial: null; nullable: boolean }

      Default parameters for this field type

      Returns DataFieldOptions & {
          blank: boolean;
          choices: undefined;
          textSearch: boolean;
          trim: boolean;
      } & { blank: boolean; initial: null; nullable: boolean }

    • get hasFormSupport(): boolean

      Does this form field class have defined form support?

      Returns boolean

    Methods

    • Parameters

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

      Returns string

    • Parameters

      • value: any

      Returns string

    • Recursively replace data references in a string change value.

      Parameters

      • raw: any
      • data: any

        An object providing replacements

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

        Additional options to configure the data replacement

      Returns string

      The expression with data references resolved

    • Internal

      Commit a prepared update to DataModel#_source.

      Parameters

      • source: object

        The parent source object within which the key field exists

      • key: string

        The named field in source to commit

      • value: object

        The new value of the field which should be committed to source

      • diff: object

        The reported change to the field

      • options: DataModelUpdateOptions

        Options which modify how this update workflow is performed.

      Returns void

    • Internal

      Update the source data for a DataModel which includes this DataField. Updates are performed depth-first; validated and recorded from leaf-nodes upwards.

      This method is responsible for preparing and validating the requested update. If the update is valid, it is responsible for updating the pending source copy and recording the diff. If the update is invalid it must avoid recording a diff or staging an update to the source copy. If validation fails, this workflow may optionally permit fallback to a valid initial value.

                                       a partial node of source data, relative to which this field belongs.
      

      Parameters

      • key: string

        The name of this field within the context of the source data.

      • value: any

        The candidate value that should be applied as an update.

      • options: DataModelUpdateOptions

        Options which modify how this update workflow is performed.

      • state: data.types.DataModelUpdateState

        Stateful data that is transacted throughout the model hierarchy during an update operation.

      Returns void

      An error if the requested update cannot be performed.

    • Internal

      Certain fields may declare joint data validation criteria. This method will only be called if the field is designated as recursive. This method should throw if any validation error occurred, even if resolved by fallback or dropping.

      Parameters

      • data: object

        Candidate data for joint model validation

      • options: object = {}

        Options which modify joint model validation

      Returns void

      An error if joint model validation fails

    • 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

    • Parameters

      • value: any
      • options: any

      Returns true | undefined

    • 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

      • Optionaloptions: object = {}

        Additional options passed to the applied function

      Returns object

      The results object

    • 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

      • value: any

        An initial requested value

      • options: any

        Additional options for how the field is cleaned

      • _state: any

        Internal state variables which are used during recursion

      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

    • 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

    • 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 an "add" 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 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

      Cast a change delta into an appropriate type to be applied to this field.

      Parameters

      • delta: any

        The change delta.

      • replacementData: object = {}

        Data used to resolve "@" expressions.

      Returns any

    • Protected

      Recursively traverse a schema and retrieve a field specification by a given path/key

      Parameters

      • parts: string[]

        The field path or property key if source is passed as an array of strings (in reverse order)

      • Optionaloptions: { source?: object; type?: object } = {}

        Additional options

        • Optionalsource?: object

          The source data of the field

        • Optionaltype?: object

          The Document type of the parent field

      Returns DataField | undefined

      The corresponding DataField definition for that field, or undefined

    • Protected

      Test whether a provided value is a valid choice from the allowed choice set

      Parameters

      • value: string

        The provided value

      Returns boolean

      Is the choice valid?

    • Protected

      For fields which have hierarchical data structures, define how their inner fields should be validated. This method is called after _validateSpecial and _validateType. It can be assumed that those tests passed. This method should throw if any validation error occurred, even if resolved by fallback or dropping.

      Parameters

      Returns boolean | void

      A boolean to indicate with certainty whether the value is valid

      An error with a specific reason the value is invalid