Logic

Adding Logic to a component allows for changing the component definition in reaction to data entered in a form. For two examples, see this page. The createLogic and createDisableLogic functions in the componentProperties package/module makes it easier to create Logic objects.

Properties

NameDescriptionDatatypeDefault
nameName of the field logic.String'My logic'
triggerWhen to trigger actions. Example:
  • trigger.type = 'simple'
  • trigger.simple.show = true
  • trigger.simple.when = 'theKey'
  • trigger.simple.eq = 'Bob'
Struct/dict
actionsThe action(s) to trigger.cell/list

Trigger property

The trigger's 'type' field may have the values 'simple', 'javascript' or 'event'. The createTrigger function in the componentProperties package/module simplifies creating a trigger.

simple

When the trigger type is 'simple', the trigger struct/dict must contain a field 'simple'. It must contain a struct/dict with fields:

  • 'show': must contain a boolean,
  • 'when': must contain the full key of another component and
  • 'eq': must contain a value that is compared against the value of the component specified in 'when'

The component that contains the Logic object is shown true/false when the other component's value equals the specified value.

javascript

When the trigger type is 'javascript', the trigger struct/dict must contain a field 'javascript'. It must contain JavaScript code that assigns a boolean to a variable 'result'. This is described in more detail in section Custom JavaScript.

event

When the trigger type is 'event', the trigger struct/dict must contain a field 'event'. It must contain the name of an event that is triggered in the form.

Actions property

The actions property must contain a cell array / list containing one or more action structs/dicts. The action's 'type' field may have the values 'property', 'value' or 'customAction'. To create a disable action the createDisableAction function in the componentProperties package/module can be used.

property

When the action type is 'property', the action struct/dict must contain a field 'property'. It must contain a struct/dict with fields:

  • 'value': the property to change
  • 'type': the data type of the property

The action struct must also contain a field 'state' containing the value the specified property must get when the trigger of the Logic object is triggered.

value

When the action type is 'value', the action struct/dict must contain a field 'value'. It must contain JavaScript code that assigns a value to a variable 'value'. This is described in more detail in section Custom JavaScript.

customAction

When the action type is 'customAction', the action struct/dict must contain a field 'customAction'. It must contain JavaScript code that assigns a value to a variable 'value'. This is described in more detail in section Custom JavaScript.

Utility functions

The componentProperties package/module contains some utility functions to make it easier to add Logic to your components.

Create Trigger

The createTrigger function can be used to define when Logic must be applied. It accepts a triggerType and triggerValue input. The trigger type and value must be one of the following combinations:

Trigger typeTrigger valueRemark
"event""EventName"Triggers when the event EventName occurs.
"trigger"trigger definition dictionary.For reusing an existing trigger.

The following trigger types and values trigger Logic when the component with key "key" has the given value. Note that data.key does not work in case of intermediate data components.

Trigger typeTrigger valueRemark
"simple"{"key", value}:
"javascript""result = data.key == value"javascript trigger syntax
"result""data.key == value"Shorter 'javascript' trigger.
"json""{"==": [{"var": "data.key"}, value]}"Uses JSON Logic syntax

Create disable action

The createDisableAction function creates a component disable action definition that can be used in a Logic object. When you use the function with disableTarget input set to false, the created action is an enable action.

Create Logic

The createLogic function creates a Logic object with the specified trigger type and value, and optional actions and component to add it to. The trigger is created by the createTrigger function, so the input options documented there also apply here.

Create disable Logic

The createDisableLogic function creates a Logic object with disable action with the given trigger type and value. The trigger is created by the createTrigger function, so the input options documented there also apply here. When a target component is specified, the Logic object is added to that component. When the function is used with the disableTarget input set to false, the created action is an enable action.

Note that adding disable Logic to a disabled component (and the other way around) does nothing. This function will show a warning on this.