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 forminputelement, such as thetextinput.Then, register the hook using the Superform API. See the example below.
Example in steps:
Adding
hook(validateEmail)to the HTMLinputelement.This calls a function
validateEmailregistered with JavaScript to check if the input is a valid email.If not, Superform triggers the corresponding error.
HTML Example
Webflow Example
Attribute Configuration
Ensure the attribute key is
sf-validationand 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
booleanvalue indicating the validity of the input.
β Read more about the registerInputValidationHook method here.
Last updated
Was this helpful?