Hook
Navigation hooks — connect JavaScript logic to determine next steps.
Setup
Attribute: sf-goto = hook(HOOK_NAME)
Where: Navigation elements, radio buttons, or radio button groups, checkboxes, or checkbox groups.
Description: Determine the next move with JavaScript logic.
Initialization
Add the
sf-goto="hook(HOOK_NAME)"
attribute to your navigation element, such as the next button.Then, register the hook using the Superform API. See the example below.
Pro Tip
Navigation hooks also support async returns, meaning you can return a promise that resolves to a string or number.
You can also chain hooks, meaning a hook can return a new hook instruction. For example, instead of returning a step name or step index, you can return
hook(NEXT_HOOK)
.
Attribute Configuration
Configuring navigation does not require any extra attributes. Just ensure the attribute key is sf-goto
and the value is hook(HOOK_NAME)
. Here are some instructions to keep in mind:
The hook should follow the format
hook(YOUR_HOOK_NAME)
.Do not register multiple hooks with the same name. The default nature of hook registration is to override.
Hook names should not contain any spaces or symbols.
Here are some dos and don'ts:
Dos and Don'ts
Do ✅
hook(my_hook)
hook(hookIsAwesome)
hook(callhook)
hook(CALLHOOK)
Don't ❌
hook(111111)
, don't use numbers as the start of the hook namehook($$$-hook)
, don't use symbols, except for underscoreshook(⚡️)
, don't use emojishook(my hook is great)
, don't use spaces
→ Read more about the registerNavigationHook
method here.
Last updated