Module: alfresco/forms/DynamicForm

alfresco/forms/DynamicForm

This module extends the standard Form widget to provide the ability to change the data and buttons displayed based upon topics published relating to various CRUD states. For example the same form can show empty (or default) fields for creating new objects or can be updated with data for existing items. The buttons will vary based on the current form state, e.g. "Delete" and "Update" will be shown for existing data, but will not be displayed when creating new items.
Author:
  • Dave Draper
License:
Source:

Members

cssRequirements :object[]

An array of the CSS files to use with this widget.
Type:
  • object[]
Default Value:
  • [{cssFile:"./css/DynamicForm.css"}]
Source:

defaultData :object

This should be configured to be an object that contains the default data set to use for creating new instances. This object will be passed to the setValue function when the "create" form state is entered.
Type:
  • object
Default Value:
  • null
Source:

formValueProperty :string

This is the property in the payload published on the subscriptionTopic that contains a value to set on the form.
Type:
  • string
Default Value:
  • null
Source:

formWidetsPropertyStringified :boolean

This indicates whether or not the formWidgetsProperty is expected to be "stringified" (e.g. it is pure JSON that requires parsing). If this is set to true (which is the default) then an attempt will be made to parse any data found.
Type:
  • boolean
Default Value:
  • true
Source:

formWidgetsProperty :string

This is the property in the payload published on the subscriptionTopic that contains the JSON model to render as form widgets.
Type:
  • string
Default Value:
  • "value"
Source:

showFormTopics :array

This should be configured to be an array of topics that when published will reveal the the form. The form is expected to be shown when an existing item is selected or when a new item should be created.
Type:
  • array
Default Value:
  • null
Source:

showInfoTopics :array

This should be configured to be an array of topics that when published will reveal the the information panel. The information panel is expected to be shown after creation, update and deletion events
Type:
  • array
Default Value:
  • null
Source:

subscriptionTopic :string

The topic that will be subscribed to in the postCreate function to trigger the redrawing of the form. It is expected that this will be configured with a custom value but a default value is provided.
Type:
  • string
Default Value:
  • "ALF_DYNAMIC_FORM_UPDATE"
Source:

Methods

allWidgetsProcessed(widgets)

Extends the default implementation to capture the form fields and update the default data object.
Parameters:
Name Type Description
widgets array The created form controls
Source:

createButtons()

Overrides the default implementation to creates the "Create", "Update" and "Save" buttons
Source:

onDynamicFormUpdate(payload)

This function is called whenever the subscriptionTopic is published on.
Parameters:
Name Type Description
payload object A payload containing a 'value' attribute with the JSON model to render
Source:

onShowCreateState(payload)

Hides the "Update" and "Delete" buttons and shows the "Create" button and updates the form to display the default data.
Parameters:
Name Type Description
payload object The details of the create state
Source:

onShowForm()

This function is called whenever the form should be displayed and the information panel hidden. The topics that when published will cause this function to be called can be configured via the showFormTopics attribute.
Source:

onShowInfo()

This function is called whenever the information panel should be displayed and the form hidden. The topics that when published will cause this function to be called can be configured via the showFormTopics attribute.
Source:

onShowUpdateState(payload)

Hides the "Create" button and shows the "Update" and "Delete" buttons. Updates the form with the requested data.
Parameters:
Name Type Description
payload object The details of the create state
Source:

postCreate()

Extends the inherited function to create a new "info" node. This node will be displayed when no item has been selected or when the last viewed item has been updated or deleted.
Source:

postCreate()

Source:

postMixInProperties()

Subscribes to
Source:

alfresco/forms/DynamicForm

This module extends the standard form to provide the ability to dynamically re-draw a form based on payload published to a subscribed topic. The published payload should contain a dot-notation property (the default is "value") that contains a form model to render. This model is expected to be a "stringified" JSON array of form control that should be rendered. If the property is actually a JavaScript object (e.g. it is not "stringified" JSON) then formWidetsPropertyStringified should be configured to be false.

The individual form controls can be set with their own value, however if an overall form value needs to be set after rendering then a dot-notation property should be configured that identifies where the form value is expected to be found in the published payload.

The form buttons will only be displayed if the form contains any controls initially and the buttons will be hidden if the payload published on the subscribed topic contains an empty array as the form model.

Author:
  • Dave Draper
License:
Source:

Examples

Basic configuration using defaults:

{
  name: "alfresco/forms/DynamicForm",
  config: {
    subscriptionTopic: "UPDATED_FORM_DETAILS",
    okButtonPublishTopic: "DYNAMIC_FORM_POST"
  }
}

Configuration for alternative, non-stringified form model with an expected form value:

{
  name: "alfresco/forms/DynamicForm",
  config: {
    subscriptionTopic: "UPDATED_FORM_DETAILS",
    okButtonPublishTopic: "DYNAMIC_FORM_POST",
    formWidgetsProperty: "widgets",
    formWidetsPropertyStringified: false,
    formValueProperty: "formValue",
  }
}
 

Members

cssRequirements :object[]

An array of the CSS files to use with this widget.
Type:
  • object[]
Default Value:
  • [{cssFile:"./css/DynamicForm.css"}]
Source:

defaultData :object

This should be configured to be an object that contains the default data set to use for creating new instances. This object will be passed to the setValue function when the "create" form state is entered.
Type:
  • object
Default Value:
  • null
Source:

formValueProperty :string

This is the property in the payload published on the subscriptionTopic that contains a value to set on the form.
Type:
  • string
Default Value:
  • null
Source:

formWidetsPropertyStringified :boolean

This indicates whether or not the formWidgetsProperty is expected to be "stringified" (e.g. it is pure JSON that requires parsing). If this is set to true (which is the default) then an attempt will be made to parse any data found.
Type:
  • boolean
Default Value:
  • true
Source:

formWidgetsProperty :string

This is the property in the payload published on the subscriptionTopic that contains the JSON model to render as form widgets.
Type:
  • string
Default Value:
  • "value"
Source:

showFormTopics :array

This should be configured to be an array of topics that when published will reveal the the form. The form is expected to be shown when an existing item is selected or when a new item should be created.
Type:
  • array
Default Value:
  • null
Source:

showInfoTopics :array

This should be configured to be an array of topics that when published will reveal the the information panel. The information panel is expected to be shown after creation, update and deletion events
Type:
  • array
Default Value:
  • null
Source:

subscriptionTopic :string

The topic that will be subscribed to in the postCreate function to trigger the redrawing of the form. It is expected that this will be configured with a custom value but a default value is provided.
Type:
  • string
Default Value:
  • "ALF_DYNAMIC_FORM_UPDATE"
Source:

Methods

allWidgetsProcessed(widgets)

Extends the default implementation to capture the form fields and update the default data object.
Parameters:
Name Type Description
widgets array The created form controls
Source:

createButtons()

Overrides the default implementation to creates the "Create", "Update" and "Save" buttons
Source:

onDynamicFormUpdate(payload)

This function is called whenever the subscriptionTopic is published on.
Parameters:
Name Type Description
payload object A payload containing a 'value' attribute with the JSON model to render
Source:

onShowCreateState(payload)

Hides the "Update" and "Delete" buttons and shows the "Create" button and updates the form to display the default data.
Parameters:
Name Type Description
payload object The details of the create state
Source:

onShowForm()

This function is called whenever the form should be displayed and the information panel hidden. The topics that when published will cause this function to be called can be configured via the showFormTopics attribute.
Source:

onShowInfo()

This function is called whenever the information panel should be displayed and the form hidden. The topics that when published will cause this function to be called can be configured via the showFormTopics attribute.
Source:

onShowUpdateState(payload)

Hides the "Create" button and shows the "Update" and "Delete" buttons. Updates the form with the requested data.
Parameters:
Name Type Description
payload object The details of the create state
Source:

postCreate()

Extends the inherited function to create a new "info" node. This node will be displayed when no item has been selected or when the last viewed item has been updated or deleted.
Source:

postCreate()

Source:

postMixInProperties()

Subscribes to
Source: