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.
- Copyright:
- Copyright (C) 2005-2020 Alfresco Software Limited
- License:
- GNU Lesser General Public License, see: Open Source Licensing
- Source:
Examples
{
name: "alfresco/forms/DynamicForm",
config: {
subscriptionTopic: "UPDATED_FORM_DETAILS",
okButtonPublishTopic: "DYNAMIC_FORM_POST"
}
}
{
name: "alfresco/forms/DynamicForm",
config: {
subscriptionTopic: "UPDATED_FORM_DETAILS",
okButtonPublishTopic: "DYNAMIC_FORM_POST",
formWidgetsProperty: "widgets",
formWidetsPropertyStringified: false,
formValueProperty: "formValue",
}
}
Extends
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()
-
- 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:
-
postMixInProperties()
-
Subscribes to
- Source: