idea-toolbox
    Preparing search index...

    Class PickOption<T>

    An option that can be picked from a list, whether the pick is single or multiple.

    It doesn't carry the selection: that belongs to whoever owns the value. Note: item is a free slot to keep the object the option was built from, so that the picked value can be resolved back to the domain without looking it up again.

    Type Parameters

    • T = any

    Hierarchy (View Summary)

    Index

    Constructors

    • Object initialization, setting all the default values.

      Type Parameters

      • T = any

      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 PickOption<T>

    Properties

    description: string

    Additional information, shown below the name.

    group: string

    What qualifies the option among the others, e.g. the customer of a location or the country of a section. When at least two options have a different one, the list shows it as a section heading.

    item?: T

    The object the option was built from; it's kept as-is and never shown.

    name: string

    The label to show; it falls back to the value.

    value: string | number

    The unique identifier of the option.

    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.

      • 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)

      • OptionaldefaultVal: any

        if set, the fallback value instead of null

      Returns any[]

      cleaned array

    • Whether the option matches a search query, on any of the text it shows.

      Parameters

      • query: string

      Returns boolean

    • 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

      • Optionaloptions: any

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

        Typical implementation:

        super.safeLoad(newData, safeData);
        this.keyAttr = safeData.keyAttr;
        this.importantAttr = safeData.importantAttr;
        this.isDraft = safeData.isDraft;
        // ...

        Note well: there is no need to call this.load(), since it's implicitly called from super.safeLoad(), which will anyway use the child version of the method.

      Returns void

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

      Parameters

      • Optionaloptions: any

        custom options to apply; they will depend on the implementations

      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;
    • Build a list of options from plain objects, leaving the ones that already are options untouched. Note: it returns a new array every time, so don't call it on a value that is recreated on every change detection (an inline literal in a template): keep the list in a field or a computed.

      Type Parameters

      • T = any

      Parameters

      Returns PickOption<T>[]