Browse and search developers
Embed SDK
Embed options and events
Reference for the embed configuration fields, the data-formit-embed attribute, the window.FormitEmbed JavaScript API, its handle methods and callbacks.
Formit embeds are configured in two places. Display settings are saved on the embed in the app and fetched at runtime. Behaviour on your page, such as callbacks and where to mount, is set through the window.FormitEmbed JavaScript API.
Data attributes
| Attribute | Required | Description |
|---|---|---|
data-formit-embed | Yes | The embed id. Elements with this attribute are mounted when the script loads and by FormitEmbed.init(). |
The SDK sets data-formit-mounted on elements it has mounted. Treat it as internal state and do not set it yourself.
Embed configuration (set in the app)
These fields are stored on the embed and returned by the public configuration endpoint. You edit them in Share, not in your HTML.
| Field | Type and range | Used by |
|---|---|---|
width, unit | number, px or % | Standard. unit applies to width only. |
height | number, px | Standard (starting height in auto mode) |
heightMode | fixed or auto | Standard |
fullscreenMobile | boolean | Standard. The SDK also applies it to slider, popover and side tab iframes, but the app shows the toggle only for Standard and Full page. |
hideHeaders | boolean | All modes |
autoFocus | boolean | All modes |
backgroundTransparency | 0 to 100 | All modes |
readUrlParams | boolean | All modes |
customParamValues | list of { key, value } | All modes |
position | left, right or bottom | Slider, Popover, Side tab |
sliderWidth | number, px | Slider. The SDK also uses it for the side tab panel width (200 to 1200px), which the app does not show for side tab. |
popupSize | large, medium or small | Popup |
buttonText | up to 100 characters | Popup, Slider, Side tab |
buttonColor | colour string | Popup, Slider, Popover, Side tab |
buttonFontSize | 10 to 48 | Popup, Slider |
buttonBorderRadius | 0 to 100 (%) | Popup, Slider |
buttonAsText | boolean | Popup, Slider |
popoverIconUrl | image URL or null | Popover, Side tab |
greetingEnabled, greetingMessage | boolean, up to 50 characters | Popover |
notificationDot | boolean | Popover |
hideForDays | 0 to 365 | Popover |
URL parameters
The SDK adds customParamValues to the form URL as query parameters. When readUrlParams is on (the default), it also copies every query parameter from the host page URL, and those win over custom values with the same key. Use this to pass campaign data such as utm_source into hidden fields. The SDK sets its own parameters (embed, hideHeaders, autoFocus, hostViewport, embedPosition and bgTransparency) first and URL parameters are applied after them, so do not use those names for your own values.
JavaScript API
| Function | Returns | Description |
|---|---|---|
FormitEmbed.init(root?) | void | Mounts every unmounted [data-formit-embed] element inside root (default document). Runs automatically when the script loads. |
FormitEmbed.mount(element, callbacks?) | Promise<void> | Mounts one element that has data-formit-embed. Accepts autoResize and the callbacks below. Does nothing if the element is already mounted, and rejects if the configuration cannot be loaded. |
FormitEmbed.createWidget(embedId, options?) | handle | Sets data-formit-embed on the container, mounts it and returns a handle. |
createPopup, createSlider, createPopover, createSidetab | handle | Same as createWidget. |
FormitEmbed.createEmbed(embedId, mode, options?) | handle | Same, with a mode argument such as popup or POPUP. |
Options for create functions
| Option | Type | Description |
|---|---|---|
container | HTMLElement or CSS selector | Where to mount. Throws if a selector matches nothing. Without it, a new div is appended to body. |
autoResize | boolean | Resize the iframe to the form’s height even when the embed’s height mode is fixed. Full page ignores it. |
onReady, onSubmit, onClose, onQuestionChanged, onHeightChanged | functions | Callbacks, described below. |
onStarted | function | Called when you call handle.open(). |
Handle methods
| Method | Effect |
|---|---|
open() | Opens the popover or side tab, or clicks the popup or slider launcher. Only works after the configuration has loaded. |
close() | Closes the panel, removes any open Formit popup, slider or full page overlay on the page, and calls onClose. |
toggle() | Opens if closed, closes if open. |
refresh() | Remounts the embed and fetches the configuration again. |
unmount() | Removes the embed from the container (and its full page overlay, if any). |
Events and callbacks
Callbacks are driven by messages from the form iframe. Elements mounted automatically from the snippet have no callbacks. To receive events, mount with FormitEmbed.mount() or a create function.
| Callback | Argument | When it fires |
|---|---|---|
onReady | none | The form inside the iframe has loaded. |
onSubmit | { formId, formVersionId } | A response was submitted successfully. Not sent when the form redirects to another URL after submit. |
onClose | none | Right after a successful submit, when a visitor closes a popup, slider, popover or side tab, or when you call close(). |
onQuestionChanged | { questionId, index, fieldType } | The visitor moved to another question. |
onHeightChanged | height (number, px) | The form’s content height changed. |
Related
Can't find what you need?