Pluggable widget type=action

0
How to execute an action in a pluggable widget defined as ‘Action’ <property key="buttonAction" type="action"> <caption>On click</caption> <description>Action to be performed when button is clicked</description> </property> Do we need to check in the code if it is a page, microflow,… or is there a way to execute the defined action directly no matter what the action stands for?
asked
2 answers
2

In your widgets code you can simply call the execute() method on the action.

You will receive the action as a prop (this.props.onScanAction). To be sure the action is available you can check the canExecute (this will check if the user can access the action like open page, call nanoflow etc). If you want to make sure the action is not triggered twice (because of double click for instance) you can check the isExecuting boolean on the action. These are all default properties of the Action in a widget. Full example below:

if(this.props.onScanAction.canExecute && !this.props.onScanAction.isExecuting){
    this.props.onScanAction.execute();
}

 

answered
0

You can use the “executeAction “ from the module “piw-utils”.

You can find it in the standard Mendix widget  https://github.com/mendix/widgets-resources in the folder “packages/tools”.

Either you duplicate it in your project as a component like below, or create a dependency.


import { executeAction } from "./components/piw-utils/src/functions";

//Trigger action on onScan event (microflow or nanoflow)
executeAction(this.props.onScanAction);

 

answered