Class CustomFieldMeta

Metadata of a custom field.

Hierarchy (view full)

Constructors

  • Object initialization, setting all the default values.

    Parameters

    • OptionalnewData: any

      the data to load, optional

    • Optionaloptions: any

      custom options to apply; they will depend on the child resource

      Usually, there is no need to implement the constructor; implicitly, it will call the load of the child resource and therefore loading all the resources with default values. If needed, this is the suggested implementation:

      super();
      this.load(x);
      // ...

    Returns CustomFieldMeta

Properties

default: any

Field default value.

description: Label

Explanation of the field.

enum?: string[]

The list of the possible values (strings); available only with type ENUM.

enumLabels?: {
    [key: string]: Label;
}

The translations of the enum keys; available only with type ENUM. Not obligatory: the fallback is always the enum key.

fieldId?: string

Id of the field.

icon: string

The icon to show to identify the field.

max?: number

Max value the field can assume; available only with type NUMBER.

min?: number

Min value the field can assume; available only with type NUMBER.

name: Label

Name of the field.

obligatory: boolean

If true, an obligatory check will be performed; ignored with type BOOLEAN.

teamId?: string

The id of the team owning the field. Optional.

The type of the custom field.

Methods

  • Return an attribute in a cleaned standard that force-cast the element.

    Parameters

    • origin: any

      the origin attribute, to cast

    • castFunction: ((x: any) => any)

      the cast function, e.g. Boolean, Number, String, x => new CustomClass(x), etc.

        • (x): any
        • Parameters

          • x: any

          Returns any

    • OptionaldefaultVal: any

      if set, the fallback value instead of null

    Returns any

    cleaned attribute

  • Return an array in a cleaned standard that force-cast each element, keeping only the valid ones.

    Parameters

    • origin: any[]

      the origin array, to cast and check

    • castFunction: ((x: any) => any)

      the cast function, e.g. x => String(x) or x => new CustomClass(x)

        • (x): any
        • Parameters

          • x: any

          Returns any

    • OptionaldefaultVal: any

      if set, the fallback value instead of null

    Returns any[]

    cleaned array

  • Set a default value for the field, based on its type.

    Returns any

    the determinated default value, based on the type

  • Get the label to show for the enum, based on the translations available; if none, returns the key.

    Parameters

    • enumKey: string
    • Optionallanguage: string
    • Optionallanguages: Languages

    Returns string

  • Load a value based on the field configuration.

    Parameters

    • newField: any

      the value to load

    Returns any

  • Load the attributes from an already existing resource and then force some attributes to assume safeData values. The function is usually used in the back-end to mix together db data with new data, without the risk of changing ids and other attributes which are managed in appositely curated scenario.

    Parameters

    • newData: any

      the data to load

    • safeData: any

      the attributes to force to specific values

    • Optionallanguages: Languages

    Returns void

  • Valide the object's attributes, performing all the checkings.

    Parameters

    Returns string[]

    errors if empty, the checkings are successfully passed.

    Typical implementation:

    const e = super.validate();
    if(this.iE(this.attr)) e.push(`attr`);
    // ...
    return e;
  • Validate a field value, based on the field configuration.

    Parameters

    • field: any

      the value to check

    Returns boolean

    return false in case of error