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.
<!-- Form Container -->
<form sf="myForm">
<!-- Step 1: Booking Type Selection -->
<div sf-step="step-1">
<p>Select your booking type:</p>
<input type="radio" name="bookingType" value="Business"> Business<br>
<input type="radio" name="bookingType" value="Economy"> Economy<br>
<button sf-goto="hook(checkBookingType)">Next</button>
</div>
<!-- Step: Business -->
<!-- Step: Economy -->
</form>
// Wait until Superform is ready
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm, allForms }) => {
// Assuming you already configured Superform with a name
const myForm = getForm("myForm");
myForm.registerNavigationHook("checkBookingType", (params) => {
console.log(params.data); // Returns form data
console.log(params.stepCount); // Returns current step index
console.log(params.progress); // Returns current progress percentage
console.log(params.scores); // Returns scores object
/**
* Here I'm checking what booking type the user has selected.
* Based on that, returning the next step details.
**/
if (params.data.bookingType === "Business") {
return "business_step";
} else {
return "economy_step";
}
});
});
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:
→ Read more about the registerNavigationHook
method here.
Last updated
Was this helpful?