Embeddable LetsForm Builder
Embed a full featured LetsForm builder in any site with a Web Component and programmatically capture the composed LetsForm JSON schema in JavaScript.
From the dashboard, click on “Create builder”
then select which UI framework to use (i.e. React+RSuite5, React+AntD, etc), the form preview size and hit the button “Save”. Then click on “Embed this LetsForm Builder” to get the JavaScript code for installing it on any website.
Follow these installing instructions
Install the LetsForm Builder Web Component
Install the LetsForm Builder web component, copy the code below between the <head>
tag of your html page
<script type="module" src="https://cdn.jsdelivr.net/npm/lets-form-builder@latest/builder.bundled.js"></script>
Mount the LetsForm Builder
Mount the LetsForm Builder in any point of your web page, paste the code
<letsform-builder
height="600"
id="my_builder"
builderId="<my-builder-id>"
emptyForm="true"
/>
Each saved LetsForm Builder has its own builderId
.
Listen to changes to the form
Each time a changes is made in the form of the LetsForm Builder, an event lf-form-changed
is triggered
on the Web Component, the event payload contains the LetsForm JSON Schema which can be used by any <LetsForm />
component
<script type="module">
document.getElementById('my_builder')
.addEventListener('lf-form-changed', event => {
console.log('LetsForm JSON Schema: ', event.detail);
});
</script>
Preload an existing LetsForm JSON schema in the builder
To edit an existing LetsForm JSON Schema in the builder, just use the .loadForm()
method:
<script type="module">
document.getElementById('my_builder')
.loadForm({
"version": 2,
"fields": [
// some fields
]
});
</script>
The LetsForm Builder is loaded into an iframe, you don’t have to wait for the iframe to be loaded completely, the Web Component will do it for you.
Listen to “Save form” event
To programmatically capture the LetsForm JSON Schema from the Builder, you can either listen to the change event
lf-form-changed
(triggered on any changes) or lf-form-saved
(only triggered when the user clicks on the “Save form”
icon in the Builder).
<script type="module">
document.getElementById('my_builder')
.addEventListener('lf-form-saved', event => {
console.log('LetsForm JSON Schema: ', event.detail);
});
</script>
The “Save form” button can be disabled in the “Settings” section.
Restrict LetsForm Builder to some domains
LetsForm Builders can be restricted to run on specific domains to avoid abuse. Click on “Settings” and enter a list
of allowed domains, follow these guidelines on
how to specify domains (i.e. http://localhost:3000
, https://my.domain.it
, etc).
Custom components in LetsForm Builder
LetsForm Builders components palette can be customized with forms or pre-configured fields fed by one or more projects.
This allows to make available to your users, preconfigured fields based on your application domain.
Make project public
Projects to be used in LetsForm builders palette need be “public”, this makes forms of the project available to the external users of LetsForm Builder (not signed in to LetsForm Designer).
Enter project detail, click on “Edit” and select visibility “Public”.
Select projects
Select which public projects may appear in the draggable section of the sidebar: click on “Settings” and expand the drop down menu “Custom components” (only public projects will be listed here)
LetsForm Builder Web Component
Properties of <letsform-builder>
Web Component
Property | Type | Description |
---|---|---|
builderId | string | The builderId to be embedded. Required |
width | number | Width of form builder |
height | number | Height of the form builder |
startWithEmptyForm | boolean | Starts with an empty form. If false, UI shows a loader while waiting for a form to be loaded with .loadForm() . Default: true |
Available events
Event anme | Arguments | Description |
---|---|---|
lf-form-changed | LetsForm JSON Schema | Triggered on every JSON schema changes in the LetsForm Builder |
lf-form-saved | LetsForm JSON Schema | Triggered when the user hits the “Save” button in the LetsForm Builder |
lf-form-ready | n/a | Triggered when the LetsForm Builder is loaded and ready |
Available methods
Event anme | Arguments | Description |
---|---|---|
clearForm | Clear the form in the Form Builder | |
loadForm | LetsForm JSON Schema | Loads a form in the Form Builder |