Function trigger
- 1 minute to read
This non-visual widget is used to execute synchronous or async functions when the input parameters change.
General info
- type:
function-trigger
Params
arguments
- an array of parameters, change of which should trigger specified callbacks.callback
- a function("{{#function <expression>}}")
or an array of functions that are executed when thearguments
change.catch
- a function("{{#function <expression>}}")
or an array of functions that are executed if thecallback
fails.enabled
- iffalse
, thecallback
will not be executed. The default value istrue
.finally
- a function("{{#function <expression>}}")
or an array of functions that are executed after thecallback
, regardless of its outcome.lock
- names of widgets that should be locked while waiting for thecallback
. The editor will display a preloader on this widget.
Example
Now, let's see how you can handle the result of selecting an option. Once an option is changed, the function-trigger
widget will output its title to the console.
{
"widgets": [
{
"name": "options",
"type": "option",
"params": {
"type": "list",
"title": "Name",
"prompt": "Choose a name",
"values": [
{ "title": "Jack" },
{ "title": "James" },
{ "title": "John" }
]
}
},
{
"name": "option-titles",
"type": "function-trigger",
"enabled": false,
"lock": [],
"params": {
"arguments": [
"{{ $['options']._.title }}",
"{{ $['options']._.title }}"
],
"callback": [
"{{ #function(var1,var2) console.log(var1,var2) }}"
],
"catch": [
"{{ #function console.error('failed') }}"
],
"finally": [
"{{ #function console.log('cleanup') }}"
]
}
}
]
}
You can find more details about the properties of this widget in AuWidgetFunctionTrigger.
For more details about configuration parameters, refer to IAuWidgetFunctionTriggerConfig.