Intro to Superform API

Harness the full power of Superform with our JavaScript SDK.

Getting Started

Initializing the Superform API is pretty simple. Check out this JavaScript example below:

// Use this snippet to get started

window.SuperformAPI = window.SuperformAPI || [];

// Subscribe to listen when Superform is ready 
window.SuperformAPI.push(({ getForm, allForms }) => {

    // Start interacting with the Superform API here
    
});

When to Use the Superform API?

Superform is powerful β€” out of the box. However, if something is not supported and you wish to extend Superform's functionalities, you can use the Superform API. We picked the best use cases you might want to use the Superform API for:


Global Superform API

The following APIs are available to interact with Superform.

Superform Class

With the Superform class, you can manually initialize Superform. Make sure not to include the sf attribute on your form container.

Syntax

Parameter
Type
Description

formName

string

The name or selector of the form container

Returns

A form instance

Superform Instance

Returns a Superform instance associated with the specified container

Usage example:

getForm(formName)

Allows you to get a form by name if it is auto-initialized using the sf attribute.

Syntax

Parameter
Type
Description

formName

string

The name of the form to retrieve

Returns

A form instance

Superform Instance

Returns a Superform instance if it exists, otherwise undefined

Usage example:

allForms()

Allows you to get an array of all initialized Superform instances.

Syntax

Returns
Type
Description

All forms

Array

An array containing all Superform instances

Usage example:


Managing Superform Instances

For advanced control of Superform instances and learn how to:

  • Retrieve Form Data: Access form values programmatically with getFormData.

  • Event Listeners: Utilize beforeStepChange, onStepChange, and onFormSubmit for custom actions.

  • Register Hooks: Implement custom logic using registerInputValidationHook and registerNavigationHook.

Visit the Superform Instance documentation.

Last updated

Was this helpful?