JavaScript API
Lime Forms exposes a JavaScript API that makes it possible to extend and control a form's behaviour from custom code. The API is available both when embedding a form on an external website and through the JavaScript tab in the form editor, which lets you write custom code that runs for that specific form.
This is primarily a feature for developers and consultants, but it is useful to know what kinds of behaviour can be achieved.
What is possible
Pre-filling fields from an external source
When the form loads, custom code can call an external service and use the response to pre-fill one or more fields automatically. For example, if the end user is already logged in to your website, their name and email address can be filled in without them having to type them again.
Reacting to what the end user enters
Custom code can be notified immediately when the end user changes the value of a field, and take action in response — for example calling an external system, updating another field, or showing a message.
Showing and hiding fields programmatically
Fields can be shown or hidden based on logic that goes beyond what the built-in conditional logic supports. For example, a field could be shown or hidden based on data fetched from an external system.
Controlling navigation in multi-step forms
In a multi-step form, custom code can navigate between steps programmatically, or intercept the end user's navigation to perform a check or async operation — such as validating data against an external system — before allowing them to proceed to the next step.
Running code before and after submission
Custom code can run immediately before the form is submitted, for example to perform a final validation or send data somewhere. It can also run after a successful submission, for example to trigger an analytics event or update the surrounding page.
Calling external services
The API includes a built-in HTTP client that custom code can use to call external services directly from the form, without needing a server-side component.
Where to write the code
Custom JavaScript for a specific form is written in the JavaScript tab in the form editor. The code runs in the context of that form whenever it is loaded by an end user.
When a form is embedded on an external website, the API is also accessible from JavaScript on the surrounding page, making it possible to integrate the form with the rest of the page — for example reading a value from the page and pre-filling it into the form, or reacting to a submission to update other content on the page.
Getting custom code built
If you are interested in extending a form with custom behaviour, contact your Lime consultant.