Add behavior whenever page is shown

#1

Is there a good way to trigger a behavior every time a page is shown? I want to reset a form each time a user visits the page, even if the page is not refreshed.

0 Likes

#2

You can create an Action under ui/content/js/customCode/Action/ that extends C3.action.Action, e.g. MyAction.js:

C3.define('C3.action.MyAction', {
  extend: 'C3.action.Action',
  config: {},
  dispatch: function (page, e) {
    . . . // do something
  }
});

Then in your page (i.e. .c3ui file), attach the action to the page render event like this:

"pageRenderActions": [
  {
    "type": "MyAction"
  }
],
1 Like

#3

@TimSchultz
Your action should be triggered by the show event instead of pageRenderAction pageRenderAction will only be triggered once when the page is first rendered.

Your action will listen on the page event if you do not specify the query field in your action

{
    "trigger": "show",
    "action": {
        "type": "ToggleComponentByPermission"
    }
},
1 Like