hook()
Run JavaScript logic for input validation criteria.
Setup
Attribute: sf-validation="hook(HOOK_NAME)"
Where: Apply to any input
element in your form.
Utilize custom JavaScript functions identified by HOOK_NAME
to conduct unique validation checks on form inputs.
Initialization
Add the
sf-validation="hook(HOOK_NAME)"
attribute to your forminput
element, such as thetext
input.Then, register the hook using the Superform API. See the example below.
Example in steps:
Adding
hook(validateEmail)
to the HTMLinput
element.This calls a function
validateEmail
registered with JavaScript to check if the input is a valid email.If not, Superform triggers the corresponding error.
HTML Example
Webflow Example
Please note: registerInputValidationHook
does not support async return. This means only boolean values are allowed as valid return types.
Attribute Configuration
Ensure the attribute key is
sf-validation
and the value ishook(HOOK_NAME)
Ensure the hook name is unique and does not contain spaces or special characters.
Do not register multiple hooks with the same name. The default nature of hook registration is to override.
Hooks must return a
boolean
value indicating the validity of the input.
Dos and Dont's
Do ✅
hook(my_hook)
hook(hookIsAwesome)
hook(callhook)
hook(CALLHOOK)
Don't ❌
hook(111111)
: Don't use numbers as the start of the hook name.hook($$$-hook)
: Don't use symbols, except for underscores.hook(⚡️)
: Don't use emojis.hook(my hook is great)
: Don't use spaces.
→ Read more about the registerInputValidationHook
method here.
Last updated