Superform by Delta Clan
✨ ClonablesSocialResourcesSuperform Home
v2
v2
  • 🏁Getting Started
    • Introduction
    • Quick Start
  • 🫀Essentials
    • Form Container
    • Step Container
    • Navigation - Overview
      • Direct
      • Logic / Conditional
      • Hook
    • Variables
      • Form Data ($f)
      • Step Index ($s)
      • Progress Percentage ($p)
      • Scoring Variables ($v)
    • Progress Bar
    • Reset
    • Radio Groups
    • Checkbox Groups
    • Cheatsheet
  • ⚙️Global Options
    • Step Delay Controls
    • Animations
      • Step Animation
      • Step Animation Duration
      • Step Animation Ease
    • Save Data & Progress
    • Pre-fill Form
    • Prevent Content Flash
    • Debug
    • Third-party Integrations
    • Cheatsheet
  • 🎛️Input Validation & Errors
    • Validation
      • length()
      • words()
      • minmax()
      • checkbox()
      • must()
      • hook()
    • Error Management
      • Automatic Error Setup
      • Manual Error Setup
  • ⚡Reactivity
    • Update Text
    • Visibility
    • Class Toggle
    • Value
    • Set Attribute
  • 🔢Score Tracking
    • Score Setup & Calculation
    • Score Ranking
  • ⌨️Accessibility
    • Enter & Backspace Bindings (↩, ⌫)
    • Checkbox & Radio Bindings
  • 🛠️Javascript SDK
    • Intro to Superform API
    • Superform Instance
    • Cheatsheet
  • 📖Additional Resources
    • WTF is an expression ? 🆕
    • Integrations
    • Tutorials
    • Changelog
    • FAQ 🚧
    • Join Discord
Powered by GitBook
On this page
  • Setup
  • Displaying Scores
  • Score Calculation Methods
  • Using Score Variables Beyond Text

Was this helpful?

  1. Score Tracking

Score Setup & Calculation

Initializing and displaying scores.

Last updated 10 months ago

Was this helpful?

Learn how to initialize and display scoring variables in your forms. Scoring variables allow you to track and show scores (or any numeric values) dynamically based on user interactions.

Setup

Attribute: sf-score

Value: Comma-separated variable names (e.g., "ross, monica")

Where: Form Container

HTML Example

<form sf="friendsForm" sf-score="ross,monica">
    <!-- Steps and content go here -->
</form>

Webflow Example

Displaying Scores

To display the scores, use the sf-react attribute with the text() function to bind the score values to elements in your form.

HTML Example:

<form sf="friendsForm" sf-score="ross,monica">
    <div sf-step="step1">
        <!-- Displaying Scores -->
        <p>Scores:</p>
        <p>Ross: <span sf-react="text($v.ross)">Zero</span>Points</p>
        <p>Monica: <span sf-react="text($v.monica)">Zero</span>Points</p>
        <button sf-goto="next">See Winner</button>
    </div>
</form>

Webflow Example:

Understanding $v

The $v variable in Superform refers to the scoring variables initialized in your form. It allows you to access and manipulate the scores dynamically. You can use $v in various contexts to create interactive and responsive form elements.

Reference:

  • $v.ross - Accesses the score variable "ross".

  • $v.monica - Accesses the score variable "monica".

Score Calculation Methods

Implementing Dynamic Scoring

Understand how to calculate scores using different methods available in Superform. Customize scoring logic to suit various form requirements.

Attribute: sf-score-calc

Where: Input elements (radio buttons, checkboxes)

Calculation Methods

  • 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

<form sf="friendsForm" sf-score="ross,monica">
    <div sf-step="step1">
        <p>Who would win in a fight?</p>
        <input type="radio" name="fightWinner" value="ross" sf-score-calc="add(checked, ross, 1)"> Ross<br>
        <input type="radio" name="fightWinner" value="monica" sf-score-calc="add(checked, monica, 1)"> Monica<br>
        <!-- Displaying Scores -->
        <p>Scores:</p>
        <p>Ross: <span sf-react="text($v.ross)">Zero</span>Points</p>
        <p>Monica: <span sf-react="text($v.monica)">Zero</span>Points</p>
        <button sf-goto="next">See Winner</button>
    </div>
</form>

Webflow Example


Using Score Variables Beyond Text

Scoring variables can also be used in various elements and contexts beyond simple text display. Here are some imaginary examples:

  • Enabling/Disabling Class:

If Ross's score is lower than Monica's activate an is-disabled class for the bonus button.

<button sf-react="class($v.ross <= $v.monica, is-disabled)">Unlock Bonus for Ross</button>

  • Showing/ Hiding Elements:

If Ross's score is more than 5, show a text with "Special reward unlocked for Ross!"

<div sf-react="visibility($v.ross > 5)">
    Special reward unlocked for Ross!
</div>

Pro Tips

  • Initialization: Ensure scoring variables are correctly set in the sf-score attribute.

  • Dynamic Display: Use sf-react to dynamically update and display scores based on user interactions.

  • Versatility: Utilize scoring variables to influence various form elements, enhancing interactivity and user engagement.

For more details on $v and other form variables, refer to the .

🔢
Superform Variables Documentation