2.6 Adding Actions to Your Page
Now that you understand the basics of the Page Data Model and Hooks, let's explore how to add actions to your page in BetterForms. This guide will walk you through the process of setting up and running actions.
Introduction to Actions
Actions are instructions that tell the BetterForms framework to perform some operation. They can be used to create interactions with the user. Actions can be executed sequentially, and some actions block the execution of the next action until they are complete.
Types of Actions
Regular Actions
showModal - Renders a modal dialog
hideModal - Hides a modal that is non-blocking
showAlert - Renders a toaster style alert
path - redirects the user to a new page
runUtilityHook - runs the
onUtility
hook passing it paramsdownloadFile - downloads a file (link) to the user
runOnCompleteHook - runs the
onComplete
hookclipboard - runs
clipboard
action allowing interaction with the clipboardcookie - Allows setting of browser side cookies
wait - Waits for specified time or event
emit - Vue event bus message emit
scrollTo - Scrolls to an element
namedAction - Runs a named action. Also requires the
name
key.function - Runs JavaScript
Authentication Actions
authLogin - Performs an authentication login
authLogout - Performs logout
authReset - Performs a password reset action
authForgot - Performs a forgotten password reset hook
authVerify - Performs a verification of the verify token
authResend - Re/sends the email verification token
authRegister - Performs a registration and if successful, runs the
onRegistrationHook
Where Actions Can Be Used
Actions can be injected in many places:
Most hook scripts
Navigation Menu Items
Form action elements (buttons)
Named Actions
*_actions
schema keys (where supported)
Adding Actions to a Page
To add actions to a page, you can use the actions
key in the page schema. This key can be either an object (for running a single action) or an array of objects (to run a series of actions).
Example: Adding a Button with Actions
Here's an example of how to add a button with actions to your page:
Example: Adding a Named Action
You can also use named actions to define a set of actions that can be called from multiple places. Here's an example of how to define a named action:
Next Steps
You now have a basic understanding of how to add actions to your page in BetterForms. As you build out your first application, you'll become more familiar with these components and how to use them effectively.
Last updated
Was this helpful?