Module: alfresco/core/WidgetsOverrideMixin

alfresco/core/WidgetsOverrideMixin

This mixin module provides a function for overriding the default widget model to be generated. This function provides a consistent way in which new widgets can be added, removed, replaced and updated.
Since:
  • 1.0.97
Author:
  • Dave Draper
License:
Source:

Methods

applyWidgetOverrides(widgets, overrides)

Applies the supplied overrides to the supplied widgets model. Each element in the overrides array should define how it should be applied to the widgets array. Given the starting widgets array:
Parameters:
Name Type Description
widgets object[] The default widgets
overrides object[] The overrides to apply
Source:
Examples

This is the default widgets model to be updated in the following examples

[
  {
    id: "WIDGET_1",
    name: "alfresco/forms/controls/TextBox",
    config: {
      fieldId: "NAME",
      label: "Name",
      description: "Enter your name",
      name: "name"
    }
  },
  {
    id: "WIDGET_2",
    name: "alfresco/forms/controls/NumberSpinner",
    config: {
      fieldId: "AGE",
      label: "Age",
      description: "How old are you?",
      name: "age"
    }
  }
]

Insert a widget at the start of the model using a targetPosition of "START"

[
  {
    id: "ADDRESS",
    targetPosition: "START",
    name: "alfresco/forms/controls/TextBox",
    config: {
      fieldId: "ADDRESS",
      label: "Address",
      description: "Where do you live?",
      name: "address"
    }
  }
]

Insert a widget at the end of the model using a targetPosition of "END"

[
  {
    id: "ADDRESS",
    targetPosition: "END",
    name: "alfresco/forms/controls/TextBox",
    config: {
      fieldId: "ADDRESS",
      label: "Address",
      description: "Where do you live?",
      name: "address"
    }
  }
]

Insert a widget before another widget using by using a targetPosition of "BEFORE" and providing a targetId

[
  {
    id: "ADDRESS",
    targetId: "WIDGET_2"
    targetPosition: "BEFORE",
    name: "alfresco/forms/controls/TextBox",
    config: {
      fieldId: "ADDRESS",
      label: "Address",
      description: "Where do you live?",
      name: "address"
    }
  }
]

Insert a widget after another widget using by using a targetPosition of "AFTER" and providing a targetId

[
  {
    id: "ADDRESS",
    targetId: "WIDGET_1"
    targetPosition: "AFTER",
    name: "alfresco/forms/controls/TextBox",
    config: {
      fieldId: "ADDRESS",
      label: "Address",
      description: "Where do you live?",
      name: "address"
    }
  }
]

Remove a widget using using the remove attribute with the id of the widget to remove.

[
  {
    id: "WIDGET_2",
    remove: true
  }
]

Replace a widget using the replace attribute with the id of the widget to replace.

[
  {
    id: "WIDGET_2",
    replace: true,
    name: "alfresco/forms/controls/TextArea",
    config: {
      fieldId: "ADDRESS",
      label: "Location",
      name: "address"
    }
  }
]

Merge new configuration into an existing widget id

[
  {
    id: "WIDGET_1",
    name: "alfresco/forms/controls/TextArea",
    config: {
      name: "Who are you?"
    }
  }
]

findWidgetToOverride(widgets, targetId) → {number}

Iterates over the supplied array of widgets until one with the supplied target id is found. The index of the widget within the supplied array is then returned.
Parameters:
Name Type Description
widgets object[] An array of widgets to iterate over
targetId string The target ID to match
Source:
Returns:
The index of the widget in the array or -1 if it could not be found.
Type
number