Named Actions (Action Scripts)
Last updated
Last updated
Named actions are action arrays ( Much like scripts in FileMaker) that can be referenced by more than one element, or more easily called from HTML elements. You can think of them like a FileMaker script. The set of actions has a name, like a script name.
formSchema.form.namedActions
These are scoped to the current page only. You can edit them in the Misc tab of the page editor.
site.content.namedActions
These are globally scoped and can be called from anywhere.
Named actions can be executed from several contexts
Context | Syntax eg | |
---|---|---|
The actions processor will first try to find the named action in the current page. If unsuccessful, the global site.namedActions
object is checked.
Named actions look like any other actions array, with just the name of the action as the key. They can either be a single action like the showCantDoThat
example, or an array of actions like goToMyAccount
.
There are some reserved named action key names that are reserved for special use cases.
onFormLoad - Global named action - These actions will run just after a form is loaded. If there are actions that are generated in an onFormRequest
hook, those actions will be queued first and the onFormLoad
actions will run after. A typical use case would be to show an empty form with a loading placeholder image, then request data from the server then render the data after, allowing the application to feel more performant.
onAppLoad - Global named action - These actions will run just after the app is loaded. This can be used to populate global app settings like user data and flags after a page is refreshed.
onLogin - ( >0.9.35) Global named action - These actions will run just after the user is authenticated. This can be used to populate global app settings like user data and flags after a user logs in.
As an action in a standard array of actions:
In an HTML element using @click
:
In this example, goToMyAccount
is the name of the named action and the {id: '12345'}
is the options array that will be passed to the named action. In JavaScript, JSON keys do not need to be in quotes.
If a namedAction is called while other actions are still in the queue, the namedAction will run first and get inserted at the front of the actions queue. You can think of this as a sub-script where the namedAction runs first and then the remaining actions continue. This allows you to reuse code and is particularly useful in the global scope.
[actions array]
"xxx_actions" : [
{ your namedActions}
]
A named action is just an action that calls other named Action scripts.
HTML
<button @click="namedAction('saveData',{person: model.person})"> ... </button>
Calling from from HTML you can use the method namedAction
JavaScript
BF.namedAction('saveData',{person: model.person})
When calling from JS, use the BF functions library.