Superform Instance
Gain total programmatic control of your Superform instance.
Last updated
Gain total programmatic control of your Superform instance.
Last updated
Superform instances allow you to utilize useful methods and properties, enabling fine-grained control over your forms.
getFormData()
With the getFormData()
method, you can retrieve form values as an object.
beforeStepChange(fn)
With the beforeStepChange
method, you can register a listener that will execute right before a step change. This is useful for performing actions like triggering events for analytics.
The params
object passed to the beforeStepChange
callback function contains the following properties:
onStepChange(fn)
With the onStepChange
method, you can register a listener that will execute on a step change. This is useful for performing actions like playing/pausing videos, playing animations, or storing user progress via third-party APIs.
The params
object passed to the onStepChange
callback function contains the following properties:
onFormSubmit(fn)
With the onFormSubmit
method, you can register a listener that will execute when the form is submitted. This is useful for performing actions like triggering events for analytics or executing your business logic.
The params
object passed to the onFormSubmit
callback function contains the following properties:
registerNavigationHook(hookName, fn)
Navigation hooks support async
returns, allowing you to return a promise that resolves to a string or number.
registerInputValidationHook(hookName, fn)
Notes
• The hook function must be synchronous; asynchronous operations should be managed outside this method.
• Using a unique hook name is crucial as reusing a hook name will overwrite the previous hook.
Registers a custom navigation hook for form elements, enabling dynamic navigation logic based on form data or other conditions. Read more about navigation hooks .
Registers a custom validation hook for form inputs. This method allows you to define complex validation logic programmatically. Read more about validation hooks .
data
Object
The current form data
stepCount
number
The current step index
progress
number
The current progress percentage (0-100)
scores
Object
Contains score data
data
Object
The current form data
stepCount
number
The current step index
progress
number
The current progress percentage (0-100)
scores
Object
Contains score data
data
Object
The current form data
stepCount
number
The current step index
progress
number
The current progress percentage (0-100)
scores
Object
Contains score data
hookName
string
A unique identifier for the hook.
fn
function
A function that executes for navigation. Receives a params
object with form data and other details.
Returns
Returns either one valid instruction
step-name
string
or Promise<string>
The callback function can return a Step Teleport by step name indicating the next step name.
Linear navigation instruction
"next"
"prev"
"previous"
"back"
or Promise<Linear Instruction>
The callback function can return a Linear navigation instruction.
Step Teleport by signed number instruction (i.e +1
, -2
or valid signed number)
Signed number as string
or Promise<Step teleport string>
The callback function can return a Step Teleport by signed number navigation instruction.
Hook instruction (i.e hook(another_Hook)
)
hook(HOOK_NAME)
or Promise<"hook(HOOK_NAME)">
The callback function can return a hook navigation instruction.
hookName
string
A unique identifier for the hook.
fn
function
A function that executes for validation. Receives a params
object with form data and other details.
Returns
true
or false
Boolean
The callback function must return a Boolean
indicating the validation result (true
for pass, false
for fail).
getFormData
Object
Retrieves form values as an object
.