JS FormBuilder is a lightweight, zero-dependency JavaScript library for creating drag-and-drop form builder interfaces.
Designed for developers who need a fast, flexible, and modern solution without being tied to large frameworks.
- Ultra Lightweight: Written in pure Vanilla JS. No jQuery, React, or Vue required.
- Zero Dependency: Uses inline SVGs for icons and scoped CSS for styling.
- Fully Customizable: Configure sidebar position, select active components, and swap icons to match your branding.
- JSON Output: Generates a standardized JSON schema ready to be stored in your database.
- Responsive: Works perfectly on both Desktop and Mobile devices.
You can use JS FormBuilder via NPM (recommended for bundlers) or by directly loading the files in the browser.
Ideal for modern projects using Vite, Webpack, React, Vue, etc.
npm i @heyitsmi/form-builder
Then import it in your Javascript file:
import { FormBuilder } from '@heyitsmi/form-builder';
import '@heyitsmi/form-builder/form-builder.css';
const builder = new FormBuilder('#builder-area');Simply download the files or use a CDN link.
<!-- 1. Load Styles -->
<link rel="stylesheet" href="https://unpkg.com/@heyitsmi/form-builder/form-builder.css">
<!-- 2. Load Library -->
<script src="https://unpkg.com/@heyitsmi/form-builder/form-builder.js"></script>
<script>
// Global class 'FormBuilder' is now available
const builder = new FormBuilder('#builder-area');
</script>Create an empty div element where the form builder will be rendered.
<div id="builder-area"></div>Call the FormBuilder class with your container selector.
const builder = new FormBuilder('#builder-area', {
// options here
});Use the getJson() method to retrieve the created form structure.
document.getElementById('save-btn').addEventListener('click', () => {
const schema = builder.getJson();
console.log(schema);
});You can customize the FormBuilder by passing an options object as the second argument.
const builder = new FormBuilder('#builder-area', {
layout: 'right', // Sidebar position ('left' or 'right')
// Define which components to show and customize them
components: [
'text',
'textarea',
{ type: 'file', label: 'Upload Document' } // Custom label
],
// Override default icons with your own SVGs
icons: {
text: '<svg>...</svg>'
}
});| Property | Type | Default | Description |
|---|---|---|---|
| layout | String | 'left' | Position of the toolbox sidebar. Options: 'left' or 'right'. |
| components | Array | null (All) | List of allowed components. Can be ID strings or configuration objects. |
| icons | Object | {} | Object to override default SVG icons. |
Use the following IDs in the components array:
- text (Short Text Input)
- textarea (Long Text Input)
- number (Number Input)
- select (Dropdown)
- radio (Single Choice)
- checkbox (Multiple Choice)
- date (Date Picker)
- file (File Upload)
Here is an example of the data generated by builder.getJson():
[
{
"id": "f_1715621",
"type": "text",
"label": "Full Name",
"required": true,
"helperText": "Enter your name as per ID",
"placeholder": "John Doe"
},
{
"id": "f_1715622",
"type": "select",
"label": "Select Department",
"required": false,
"options": [
{ "label": "Marketing", "value": "Marketing" },
{ "label": "IT Support", "value": "IT Support" }
]
}
]Contributions are always welcome! Please create a Pull Request or report an Issue if you find any bugs.
- Fork this repository.
- Create a feature branch (
git checkout -b feature-new). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-new). - Open a Pull Request.
This project is licensed under the MIT License — free for personal and commercial use.