Module: alfresco/forms/controls/utilities/RulesEngineMixin

alfresco/forms/controls/utilities/RulesEngineMixin

This mixin provides the ability to evaluate form control rules that define whether or not a given attribute is in a positive or negative state based on the changing values of other fields within the same form. The contents of this module were originally part of the BaseFormControl (into which this module is now mixed in) but was abstracted in order for the rules engine to be easily applied to other form modules (in particular the ability to support banner display with Forms).
Since:
  • 1.0.32
Author:
  • Dave Draper
License:
Source:

Members

_rulesEngineData :object

This holds all the data about rules that need to be processed for the various attributes of the widget. By default this will handle rules for visibility, requirement and disability.
Type:
  • object
Default Value:
  • null
Source:

Methods

_processCallbacksConfig(attribute, callbacks)

The payload of property value changing publications should have the following attributes... 1) The name of the property that has changed ("name") 2) The old value of the property that has changed ("oldValue") 3) The new value of the property that has changed ("value") Callbacks should take the following arguments (nameOfChangedProperty, oldValue, newValue, callingObject, attribute)
Parameters:
Name Type Description
attribute string
callbacks object
Source:

evaluateRule(rulesEngineData, key) → {boolean}

Parameters:
Name Type Description
rulesEngineData object The data required to evaluate the rule
key string The current key to use in the rulesEngineData
Since:
  • 1.0.34
Source:
Returns:
Whether or not the rule evaluated successfully
Type
boolean

evaluateRules(attribute, config, widget, payload)

This function evaluates all the rules configured for a particular attribute (e.g. "visibility") for the current form control. It is triggered whenever one of the other fields configured as part of a rule changes, but ALL the rules are evaluated for that attribute.
Parameters:
Name Type Argument Default Description
attribute string
config object The full configuration for rules processing
widget object <optional>
this The widget to apply rules changes to (defaults to the calling object, i.e. this)
payload object The publication posted on the topic that triggered the rule
Source:

processRule(attribute, config, widget, rule, index)

This function processes an individual attribute rule (e.g. to change the visibility, disablement or requirement status).
Parameters:
Name Type Argument Default Description
attribute string The attribute that the rule effects (e.g. visibility)
config object The full configuration for rules processing
widget object <optional>
this The widget to apply rules changes to (defaults to the calling object, i.e. this)
rule object The rule to process.
index number The index of the rule.
Source:

processRulesConfig(attribute, config, widget)

This function sets up the subscriptions for processing rules relating to attributes.
Parameters:
Name Type Argument Default Description
attribute string E.g. visibility, editability, requirement
config object The full configuration for rules processing
widget object <optional>
this The widget to apply rules changes to (defaults to the calling object, i.e. this)
Source:

ruleValueComparator(currentValue, targetValue)

The default comparator function used for comparing a rule value against the actual value of a field. Note that the target value is expected to be an object from the arrays (assigned to the "is" or "isNot" attribute) and by default the "value" attribute of those objects are compared with the current value of the field. It is possible to override this comparator to allow a more complex comparison operation. It's important to note that values are compared as strings. This is done to ensure that booleans can be compared. This is important as it should be possible to construct rules dynamically and values should be entered as text.
Parameters:
Name Type Description
currentValue object The value currently
targetValue object The value to compare against
Source:

<inner> processConfig(attribute, config, widget)

This function is reused to process the configuration for the visibility, disablement and requirement attributes of the form control. The format for the rules is as follows:

"visibilityConfig": {
   "initialValue": true,
   "rules": [
      {
         "targetId": "fieldId1",
         "is": ["a", "b", "c"],
         "isNot": ["d", "e", "f"]
      }
   ],
   "callbacks": {
         "id": "functionA"
   }
}

This structure applied to the following attributes:

Parameters:
Name Type Argument Default Description
attribute string
config object
widget object <optional>
this The widget to apply rules changes to (defaults to the calling object, i.e. this)
Source: