Skip to main content

Loading form definitions

The builder stores the complete form structure in a single JavaScript object called the form definition. It includes all the properties and settings of the elements used in the form. Loading a form is as simple as feeding a form definition to the builder. This guide shows you how to do that.

▶️ Start the builder with a form

To start a new builder instance with a form, use the static open method to create a new builder instance and supply the form that needs to be loaded right away.

import { Builder } from "tripetto";

// Open the builder with the form* Form definition here */);

// You can use the second parameter to configure the builder* Form definition here */, {
onChange: (definition) => {
console.log("A change was made!");

📂 Loading a form

When you have a builder instance, you can call the load method to load another form. You can also use the definition property and set it to another form. The result is the same, the current form gets cleared and the supplied form loaded.

import { Builder } from "tripetto";

// Create a new builder instance
const builder = new Builder();

// Open the builder;

// Load a form
builder.load(/* Form definition here */);

// Or use the definition property
builder.definition = /* Form definition here */;

👩‍💻 Simple AJAX example

The actual loading (fetching) of a form definition from a data store is entirely up to you. You could, for example, use an AJAX call to fetch a form from a server and then supply it to the builder.

import { Builder } from "tripetto";

const response = await fetch("/example-form.json");
const form = await response.json();;