### Initialize Superform with Basic Form Container (HTML)
Source: https://deltaclan.gitbook.io/superform/getting-started/quick-start
To initialize Superform for a specific form, add the `sf='formName'` attribute to the form's container element. This example shows a `div` wrapping a `form` tag, which will be recognized by Superform for initialization.
```HTML
```
--------------------------------
### HTML Example for Dynamic Form Prefilling
Source: https://deltaclan.gitbook.io/superform/global-options/pre-fill-form
Demonstrates how to set up a form container with `sf-prefill-url="true"` for dynamic URL pre-filling, allowing real-time updates and edits. This setup ensures that as users interact with the form, the URL parameters update accordingly.
```HTML
```
--------------------------------
### Retrieve All Superform Instances with JavaScript
Source: https://deltaclan.gitbook.io/superform/js-sdk/intro-to-superform-api
This example demonstrates how to use the `allForms` method to get an array of all Superform instances that have been initialized on the page. It also shows an alternative way to access the `allForms` method directly from the `SuperformAPI` object.
```javascript
// Use this snippet to get started
window.SuperformAPI = window.SuperformAPI || [];
// Subscribe to listen when Superform is ready
window.SuperformAPI.push(({ getForm, allForms }) => {
/**
* In this example, we are fetching all Superform instances
**/
const myAllForms = allForms; // Returns all Superform instances as an array
console.log(myAllForms);
/**
* Another method to fetch all Superform instances
**/
const myAllForms1 = SuperformAPI.allForms; // Returns all Superform instances as an array
console.log(myAllForms1);
});
```
--------------------------------
### HTML Example: Single Sibling Error Detection
Source: https://deltaclan.gitbook.io/superform/input-validation-and-errors/error-management/automatic-error-setup
Demonstrates Superform's automatic error detection where an error message is placed as a direct sibling to an input field. Superform recognizes keywords like 'error' in the class name to link the message.
```HTML
Name is required
```
--------------------------------
### HTML Example: Error Above and Below Input
Source: https://deltaclan.gitbook.io/superform/input-validation-and-errors/error-management/automatic-error-setup
Shows Superform's advanced proximity context, detecting error messages both above (one sibling up) and below (two siblings down) an input field. This highlights flexible error placement without explicit attributes.
```HTML
!!!!! BE CAREFUL !!!!!!!!!
!
Please enter a valid name.
```
--------------------------------
### HTML Example: Linear Superform Navigation
Source: https://deltaclan.gitbook.io/superform/essentials/navigation-overview/direct
Illustrates the use of the `sf-goto` attribute with `next`, `back`, or `prev` values for sequential navigation in a Superform.
```HTML
sf-goto = next | back | prev
```
--------------------------------
### Include Superform JavaScript Library
Source: https://deltaclan.gitbook.io/superform/getting-started/quick-start
Add this script to the section of your Webflow page or HTML file to load the Superform library. The `defer` attribute ensures the script executes after the HTML is parsed, preventing render-blocking.
```HTML
```
--------------------------------
### HTML Example: Two Sibling Errors Detection
Source: https://deltaclan.gitbook.io/superform/input-validation-and-errors/error-management/automatic-error-setup
Illustrates Superform's ability to detect error messages when there are two sibling elements between the input and the error message. The 'error' keyword in the class name facilitates automatic linking.
```HTML
!
Email is required
```
--------------------------------
### HTML Example: Setting Superform Step Animation Easing
Source: https://deltaclan.gitbook.io/superform/global-options/animations/step-animation-ease
Illustrates how to configure the `sf-step-animation-ease` attribute on a Superform container in HTML. This example shows its application alongside `sf-step-animation` and `sf-step-animation-duration` to create a multi-step form with custom animation properties.
```HTML
```
--------------------------------
### Superform Instance: onStepChange(fn) JavaScript Usage Example
Source: https://deltaclan.gitbook.io/superform/js-sdk/superform-instance
JavaScript example demonstrating how to use onStepChange() to control video playback based on the current form step, pausing or playing as the user navigates.
```javascript
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm, allForms }) => {
const myForm = getForm("myForm");
const myVideo = document.getElementById("myVideo");
myForm.onStepChange((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
/**
* Assuming a video element is present on the first step,
* auto-play when the user is on the first step. On step change,
* pause the video.
**/
if (params.stepCount === 0) {
myVideo.play();
} else {
myVideo.pause();
}
});
});
```
--------------------------------
### Superform Instance: beforeStepChange(fn) JavaScript Usage Example
Source: https://deltaclan.gitbook.io/superform/js-sdk/superform-instance
JavaScript example demonstrating how to use beforeStepChange() to log form parameters and send custom analytics events before a form step transition.
```javascript
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm, allForms }) => {
const myForm = getForm("myForm");
myForm.beforeStepChange((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
// Sending custom event for analytics
gtag("event", "step_event", {
"step_index": params.stepCount,
"progress": params.progress
});
});
});
```
--------------------------------
### Define Form Steps with `sf-step` Attribute (HTML)
Source: https://deltaclan.gitbook.io/superform/getting-started/quick-start
Use the `sf-step` attribute on `div` elements to define individual steps within a Superform. Each step should have a unique name. This enables multi-step functionality, validation, and reactivity, even for single-step forms.
```HTML
```
--------------------------------
### HTML Example: Superform Teleport by Number of Steps
Source: https://deltaclan.gitbook.io/superform/essentials/navigation-overview/direct
Demonstrates using the `sf-goto` attribute with numerical values (`+N` or `-N`) to skip forward or backward a specified number of steps in a Superform.
```HTML
sf-goto = +1 | -1 | +5 | -3 | +10 and so on..
```
--------------------------------
### Superform Instance: getFormData() JavaScript Usage Example
Source: https://deltaclan.gitbook.io/superform/js-sdk/superform-instance
Full JavaScript example demonstrating how to retrieve and log form data using getFormData() within the Superform API context.
```javascript
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm, allForms }) => {
const myForm = getForm("myForm");
const formData = myForm.getFormData(); // Returns form data as an object
console.log(formData); // {email: "name@example.com", ...}
});
```
--------------------------------
### Manually Initialize Superform Instance with JavaScript
Source: https://deltaclan.gitbook.io/superform/js-sdk/intro-to-superform-api
This example illustrates how to manually create a new Superform instance using the Superform class constructor. It's particularly useful for integrating Superform into environments where automatic initialization via the 'sf' attribute is not desired, such as in Wized projects.
```javascript
// Use this snippet to get started
window.SuperformAPI = window.SuperformAPI || [];
// Subscribe to listen when Superform is ready
window.SuperformAPI.push(({ getForm, allForms }) => {
/**
* In this example, we are initializing Superform for the #myForm container
**/
const myForm = new Superform("#myForm");
console.log(myForm);
});
```
--------------------------------
### Control Element Visibility Based on Score Threshold
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
This Superform example shows how to dynamically control the visibility of a div element. The 'Special reward unlocked for Ross!' message will only be displayed if the score variable '$v.ross' is greater than 5.
```HTML
Special reward unlocked for Ross!
```
--------------------------------
### Superform Friends Quiz HTML Example
Source: https://deltaclan.gitbook.io/superform/essentials/variables/scoring-variables-usdv
This HTML example demonstrates how to create a simple quiz using Superform's scoring variables. It shows how to initialize scoring variables (sf-score), calculate scores based on radio button selections (sf-score-calc), and display real-time scores and the winner using reactivity (sf-react). The example uses ross and monica as scoring variables.
```html
Final Winner:
```
--------------------------------
### Mount Superform to a form container using HTML
Source: https://deltaclan.gitbook.io/superform/essentials/form-container
This HTML example shows how to mount the Superform library to a specific form by wrapping it in a `div` element with the `sf` attribute. The `sf` attribute's value, such as 'myForm', acts as a unique identifier for the form, enabling Superform's features like validation, reactivity, and multi-step support. This setup also allows programmatic access to the form using the `getForm()` function, and multiple Superform instances can exist on a single page.
```HTML
```
--------------------------------
### 1. Step Tabs HTML Example
Source: https://deltaclan.gitbook.io/superform/essentials/variables/step-index-usds
This HTML example demonstrates creating interactive step tabs and corresponding form content using Superform. It utilizes `sf-react` to dynamically apply an 'is-active' class to tabs based on the `$s` (step index) variable, and `sf-step` to define content sections for each step, enabling multi-step form navigation.
```HTML
Step 1
Step 2
Step 3
Step 1 Content
Step 2 Content
Step 3 Content
```
--------------------------------
### Implement Dynamic Score Calculation with sf-score-calc (HTML)
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
Illustrates how to use the sf-score-calc attribute on radio buttons to dynamically update scores. When a radio button is selected, it adds 1 to the corresponding score variable ('ross' or 'monica'), demonstrating real-time score tracking.
```HTML
```
--------------------------------
### Toggle Class Based on Score Comparison
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
This Superform example demonstrates how to dynamically add or remove the 'is-disabled' class to a button based on a comparison between two score variables, '$v.ross' and '$v.monica'. The button will be disabled if Ross's score is less than or equal to Monica's.
```HTML
```
--------------------------------
### HTML Example for Resetting Superform Before Submission
Source: https://deltaclan.gitbook.io/superform/essentials/reset
Shows how to use a native HTML input of type 'reset' in conjunction with the 'sf-goto' attribute to simulate a reset within the normal form flow, allowing users to clear current data and return to a specified step.
```HTML
```
--------------------------------
### Initialize Superform Score Variables (HTML)
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
Demonstrates how to initialize scoring variables 'ross' and 'monica' on a Superform container using the sf-score attribute. This prepares the form to track and manage dynamic numeric values.
```HTML
```
--------------------------------
### Superform onFormSubmit Callback Usage Example
Source: https://deltaclan.gitbook.io/superform/js-sdk/superform-instance
Demonstrates how to use the `onFormSubmit` callback function to access form data, step information, progress, and scores, and how to integrate with analytics using `gtag`.
```javascript
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm, allForms }) => {
const myForm = getForm("myForm");
const myVideo = document.getElementById("myVideo");
myForm.onFormSubmit((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
// Sending custom event for analytics
gtag("event", "lead_capture", {
"interest": params.data.interest,
"rating": params.scores.rating
});
});
});
```
--------------------------------
### Superform sf-score-calc Attribute Methods (APIDOC)
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
Documents the sf-score-calc attribute used on input elements to define dynamic score calculations. It lists the available methods (add, minus, multiply, divide) and their required parameters for conditional score manipulation.
```APIDOC
`add(condition, variable, value)`: Adds value to variable if condition is `true`.
`minus(condition, variable, value)`: Subtracts value from variable if condition is `true`.
`multiply(condition, variable, value)`: Multiplies variable by value if condition is `true`.
`divide(condition, variable, value)`: Divides variable by value if condition is `true`.
```
--------------------------------
### HTML Example for checkbox() Validation
Source: https://deltaclan.gitbook.io/superform/input-validation-and-errors/validation/checkbox
This HTML snippet demonstrates how to apply the `checkbox()` validation to a checkbox group using `sf-checkbox-group` and `sf-validation` attributes. It ensures that between 2 and 4 checkboxes are selected from the group, providing a practical example of its implementation.
```html
```
--------------------------------
### Superform registerNavigationHook Usage Example
Source: https://deltaclan.gitbook.io/superform/js-sdk/superform-instance
Illustrates how to register a navigation hook to implement conditional navigation based on form data, returning different step names depending on the `bookingType`.
```javascript
// Wait for Superform to be ready before registering hooks
window.SuperformAPI = window.SuperformAPI || [];
window.SuperformAPI.push(({ getForm }) => {
const myForm = getForm("myForm");
// Register a navigation hook for conditional navigation
myForm.registerNavigationHook("checkNavigation", (params) => {
const { data, stepCount, progress, scores } = params;
// Example condition for navigation
if (data.bookingType === "Business") {
return "business_step";
} else {
return "economy_step";
}
});
});
```
--------------------------------
### Superform `sf-prefill-url` Attribute API Reference
Source: https://deltaclan.gitbook.io/superform/global-options/pre-fill-form
Comprehensive documentation for the `sf-prefill-url` attribute in Superform, detailing its setup, behavior, and interaction with `sf-save-progress`. It outlines two distinct usage options: dynamic data prefilling and static link generation, along with best practices.
```APIDOC
Attribute: sf-prefill-url
Value: true
Location: Form Container
Description: Automatically fills form fields using URL query parameters.
Interaction with sf-save-progress: Local storage data takes precedence unless specific fields are missing, then URL data is used.
Usage Options:
Option A: Dynamic Data Prefilling
Setup: Permanent sf-prefill-url="true"
Behavior: Dynamically manages data via URL parameters; real-time updates and edits. URL parameters update as users input/modify data.
User Interaction: Shared links allow viewing/editing based on latest URL data. Changes saved and reflected in URL for pause/resume.
Ideal For: Collaborative or lengthy forms, multiple sessions, ensuring data integrity and continuity.
Option B: Static Link Generation
Setup: Temporarily activate sf-prefill-url="true" to generate URL, then remove attribute.
Behavior: Captures form's state at link creation. Removing attribute locks data, preventing further changes.
User Interaction: Static snapshot of form data. Recipients see form exactly as it was when link created.
Ideal For: Uniformity, distributing registration forms (e.g., Google Forms "Get Prefilled Link").
Best Practices:
Data Precedence: When combined with sf-save-progress, local storage data takes precedence over URL data, unless specific fields are missing.
Link Stability: For consistent information, use sf-prefill-url initially, then remove it post-link creation to maintain data integrity.
```
--------------------------------
### HTML Example: Superform Teleport to Named Step
Source: https://deltaclan.gitbook.io/superform/essentials/navigation-overview/direct
Shows how to use the `sf-goto` attribute with a specific step name (e.g., `step-name`) to jump directly to a non-linear form section in Superform.
```HTML
sf-goto = step-name
```
--------------------------------
### Superform $v Variable Access Reference (APIDOC)
Source: https://deltaclan.gitbook.io/superform/score-tracking/score-setup-and-calculation
Explains the $v variable in Superform, which provides access to initialized scoring variables. This reference details how to specifically access individual score variables for dynamic use within form elements.
```APIDOC
`$v.ross` - Accesses the score variable "ross".
`$v.monica` - Accesses the score variable "monica".
```
--------------------------------
### HTML Example for Resetting Superform Data After Submission
Source: https://deltaclan.gitbook.io/superform/essentials/reset
Demonstrates how to use an HTML input of type 'reset' with the 'sf-goto' attribute to return to a specific step (e.g., 'step-1') after a form submission, allowing the user to fill out the form again.
```HTML
Success! If you want to go again, hit "Retry"!
```
--------------------------------
### HTML Superform: Dynamic Branching with Age-Based Logic
Source: https://deltaclan.gitbook.io/superform/essentials/navigation-overview/logic-conditional
This HTML example demonstrates a Superform that implements dynamic navigation based on a user's age input. It uses `sf-logic` to direct users to either an 'adult' or 'minor' step, showcasing conditional routing within a form.
```HTML
```
--------------------------------
### HTML Example: Enable Enter Key Binding for Next Button
Source: https://deltaclan.gitbook.io/superform/accessibility/enter-and-backspace-bindings
This HTML snippet demonstrates how to explicitly enable the Enter key binding (`sf-bind-enter="true"`) on a button. When pressed, the Enter key will trigger the `sf-goto="next"` action, navigating the user to the next step in a form.
```HTML
```
--------------------------------
### HTML Example for Superform words() Validation
Source: https://deltaclan.gitbook.io/superform/input-validation-and-errors/validation/words
Demonstrates how to apply the `sf-validation="words(MIN_WORDS, MAX_WORDS)"` attribute to a `