Convert Figma logo to code with AI

formio logoformio.js

JavaScript powered Forms with JSON Form Builder

1,862
1,056
1,862
148

Top Related Projects

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.

33,863

Build forms in React, without the tears 😭

📋 React Hooks for form state management and validation (Web + React Native)

🏁 Framework agnostic, high performance, subscription-based form state management

Quick Overview

Form.io is a powerful JavaScript library for building web forms. It provides a comprehensive set of tools and components for creating dynamic, responsive forms with advanced features like conditional logic, data integration, and custom layouts.

Pros

  • Extensive set of form components and widgets
  • Supports both client-side and server-side form rendering
  • Integrates well with popular frameworks like React, Angular, and Vue
  • Robust API for customization and extension

Cons

  • Steep learning curve for advanced features
  • Large bundle size, which may impact performance for smaller projects
  • Documentation can be overwhelming for beginners
  • Some features require a paid subscription

Code Examples

Creating a simple form:

const form = new Formio.Form(document.getElementById('formio'), {
  components: [
    {
      type: 'textfield',
      key: 'firstName',
      label: 'First Name'
    },
    {
      type: 'textfield',
      key: 'lastName',
      label: 'Last Name'
    },
    {
      type: 'button',
      action: 'submit',
      label: 'Submit'
    }
  ]
});

Adding conditional logic:

const form = new Formio.Form(document.getElementById('formio'), {
  components: [
    {
      type: 'checkbox',
      key: 'subscribe',
      label: 'Subscribe to newsletter'
    },
    {
      type: 'email',
      key: 'email',
      label: 'Email',
      conditional: {
        json: { '===': [{ var: 'data.subscribe' }, true] }
      }
    }
  ]
});

Handling form submission:

form.on('submit', (submission) => {
  console.log('Form submitted:', submission.data);
  // Handle form submission, e.g., send data to server
});

Getting Started

  1. Install Form.io via npm:

    npm install formiojs
    
  2. Include the library in your project:

    import { Form } from 'formiojs';
    import 'formiojs/dist/formio.full.min.css';
    
  3. Create a form in your HTML:

    <div id="formio"></div>
    
  4. Initialize the form in your JavaScript:

    const form = new Form(document.getElementById('formio'), {
      components: [
        // Add your form components here
      ]
    });
    
  5. Handle form events:

    form.on('submit', (submission) => {
      // Process form submission
    });
    

Competitor Comparisons

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal, with a smaller footprint than formio.js
  • Simple syntax and easy learning curve for developers
  • Integrates seamlessly with existing HTML, requiring less JavaScript

Cons of Alpine

  • Less feature-rich compared to formio.js for complex form building
  • Limited ecosystem and fewer pre-built components
  • May require more custom code for advanced form functionality

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = true">Open Modal</button>
    <div x-show="open">Modal Content</div>
</div>

formio.js:

Formio.createForm(document.getElementById('formio'), {
  components: [
    { type: 'textfield', key: 'firstName', label: 'First Name' },
    { type: 'textfield', key: 'lastName', label: 'Last Name' },
    { type: 'button', action: 'submit', label: 'Submit' }
  ]
});

Alpine focuses on enhancing existing HTML with minimal JavaScript, while formio.js provides a more comprehensive form-building solution with pre-defined components and a JavaScript-driven approach. Alpine is better suited for simpler interactive elements, whereas formio.js excels in creating complex, dynamic forms with advanced features and validations.

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design

Pros of react-admin

  • More comprehensive admin interface framework with built-in data providers and authentication
  • Extensive documentation and active community support
  • Seamless integration with Material-UI for consistent design

Cons of react-admin

  • Steeper learning curve due to its opinionated structure
  • Less flexibility for custom form building compared to formio.js
  • Primarily focused on admin interfaces, which may limit its use in other scenarios

Code Comparison

react-admin:

import { Admin, Resource } from 'react-admin';
import { PostList, PostEdit, PostCreate } from './posts';

const App = () => (
  <Admin dataProvider={...}>
    <Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate} />
  </Admin>
);

formio.js:

Formio.createForm(document.getElementById('formio'), {
  components: [
    { type: 'textfield', key: 'firstName', label: 'First Name' },
    { type: 'textfield', key: 'lastName', label: 'Last Name' },
    { type: 'button', action: 'submit', label: 'Submit' }
  ]
});

The code examples highlight the different approaches: react-admin focuses on creating admin interfaces with predefined resources, while formio.js emphasizes flexible form creation with various components.

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.

Pros of survey-library

  • More comprehensive documentation and examples
  • Wider range of question types and customization options
  • Better support for localization and multi-language surveys

Cons of survey-library

  • Steeper learning curve due to more complex API
  • Larger file size, which may impact page load times
  • Less integration with backend systems compared to formio.js

Code Comparison

survey-library:

const survey = new Survey.Model({
  questions: [
    { type: "text", name: "name", title: "Your name:" },
    { type: "rating", name: "rating", title: "Please rate:" }
  ]
});

formio.js:

Formio.createForm(document.getElementById('formio'), {
  components: [
    { type: "textfield", key: "name", label: "Your name:" },
    { type: "number", key: "rating", label: "Please rate:" }
  ]
});

Both libraries allow for creating surveys or forms with various question types. survey-library offers more built-in question types and customization options, while formio.js provides a simpler API and better integration with backend systems. The choice between the two depends on the specific requirements of your project, such as the complexity of the surveys, need for backend integration, and desired customization level.

33,863

Build forms in React, without the tears 😭

Pros of Formik

  • Lightweight and focused on React form management
  • Excellent TypeScript support and type safety
  • Integrates well with existing React ecosystems and libraries

Cons of Formik

  • Less feature-rich compared to Form.io's comprehensive form builder
  • Requires more manual setup for complex form scenarios
  • Limited out-of-the-box UI components

Code Comparison

Formik:

import { Formik, Form, Field } from 'formik';

<Formik initialValues={{ name: '' }} onSubmit={handleSubmit}>
  <Form>
    <Field name="name" />
    <button type="submit">Submit</button>
  </Form>
</Formik>

Form.io:

import { Form } from '@formio/react';

<Form
  form={formDefinition}
  onSubmit={handleSubmit}
/>

Formik focuses on managing form state and validation in React applications, providing a lightweight solution with excellent TypeScript support. It integrates well with existing React ecosystems but requires more manual setup for complex scenarios.

Form.io offers a more comprehensive form building solution with a rich set of features and UI components out-of-the-box. It provides a powerful form builder and renderer, making it easier to create complex forms quickly. However, it may be considered heavier and less flexible for simpler use cases compared to Formik.

📋 React Hooks for form state management and validation (Web + React Native)

Pros of react-hook-form

  • Lightweight and performant, with minimal re-renders
  • Easy integration with React ecosystem and existing projects
  • Flexible validation system with built-in and custom rules

Cons of react-hook-form

  • Limited to React applications, not framework-agnostic
  • Less out-of-the-box features compared to formio.js
  • Steeper learning curve for complex form scenarios

Code Comparison

react-hook-form:

import { useForm } from "react-hook-form";

function App() {
  const { register, handleSubmit } = useForm();
  const onSubmit = data => console.log(data);
  
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("firstName")} />
      <input {...register("lastName")} />
      <input type="submit" />
    </form>
  );
}

formio.js:

Formio.createForm(document.getElementById('formio'), {
  components: [
    {
      type: 'textfield',
      key: 'firstName',
      label: 'First Name'
    },
    {
      type: 'textfield',
      key: 'lastName',
      label: 'Last Name'
    },
    {
      type: 'button',
      action: 'submit',
      label: 'Submit'
    }
  ]
}).then(function(form) {
  form.on('submit', function(submission) {
    console.log(submission);
  });
});

The code comparison shows that react-hook-form is more tightly integrated with React components, while formio.js uses a more declarative approach to form creation.

🏁 Framework agnostic, high performance, subscription-based form state management

Pros of final-form

  • Lightweight and minimal, with a smaller bundle size
  • Framework-agnostic, easily integrates with various UI libraries
  • Highly performant, especially for large forms

Cons of final-form

  • Less out-of-the-box functionality compared to formio.js
  • Requires more setup and configuration for complex form scenarios
  • Smaller community and ecosystem

Code Comparison

final-form:

import { createForm } from 'final-form'

const form = createForm({
  onSubmit: async values => {
    // submit logic
  }
})

formio.js:

import FormioForm from 'formiojs/Form'

const form = new FormioForm(document.getElementById('formio'), {
  components: [
    // form components
  ]
})

Summary

final-form is a lightweight, flexible form management library that excels in performance and framework independence. It's ideal for developers who prefer a minimalist approach and want fine-grained control over their form implementation.

formio.js, on the other hand, offers a more comprehensive solution with built-in components and features, making it suitable for rapid development of complex forms. It has a steeper learning curve but provides more out-of-the-box functionality.

The choice between the two depends on project requirements, desired level of control, and development preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

JavaScript powered forms and SDK for Form.io

This library is a plain JavaScript form renderer and SDK for Form.io. This allows you to render the JSON schema forms produced by Form.io and render those within your application using plain JavaScript, as well as provides an interface SDK to communicate to the Form.io API's. The benefits of this library include.

  • Plain JavaScript implementation using ES6 and Modern practices (no jQuery, Angular, React, or any other framework dependency)
  • Renders a JSON schema as a webform and hooks up that form to the Form.io API's
  • Complete Form Builder which creates the JSON schema used to render the forms.
  • Nested components, layouts, Date/Time, Select, Input Masks, and many more included features
  • Full JavaScript API SDK library on top of Form.io

Examples and Demonstration

To find out more about this library as well as see a demonstration of what you can do with this library, go to the Examples and Demo site @ https://formio.github.io/formio.js

Installation

To install this SDK into your project, you can use the following command within your terminal.

npm install --save @formio/js

Form Building

This library has a very powerful JSON form builder, and can be used like the following.

<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
    <script src='https://cdn.form.io/js/formio.full.min.js'></script>
  </head>
  <body>
    <div id='builder'></div>
    <script type='text/javascript'>
      Formio.builder(document.getElementById('builder'), {}, {});
    </script>
  </body>
</html>

This will create a robust Form builder embedded right within your own application. See Our Demo Page for an example.

Form Builder Documentation

Go to the Form Builder Documentation for a full documentation on how the open source form builder works.

Form Rendering

The following is a simple example on how to render a form within your HTML application.

<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
    <script src="https://cdn.form.io/js/formio.embed.js"></script>
  </head>
  <body>
    <div id='formio'></div>
    <script type='text/javascript'>
      Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/example');
    </script>
  </body>
</html>

This will render the following form within your application.

Alt text

You can also render JSON directly instead of referencing the embed URL from Form.io.

Formio.createForm(document.getElementById('formio'), {
  components: [
    {
      type: 'textfield',
      key: 'firstName',
      label: 'First Name',
      placeholder: 'Enter your first name.',
      input: true
    },
    {
      type: 'textfield',
      key: 'lastName',
      label: 'Last Name',
      placeholder: 'Enter your last name',
      input: true
    },
    {
      type: 'button',
      action: 'submit',
      label: 'Submit',
      theme: 'primary'
    }
  ]
});

This will render the JSON schema of the form within your application.

JSFiddle Example

A great way to play around with this renderer is to use JSFiddle, which serves as a good sandbox environment. Here is an example that you can fork and make your own!

http://jsfiddle.net/travistidwell/z63jvwkp/

Form Renderer Documentation

For a more complete documentation of how to utilize this library within your application go to the Form Renderer documentation.

Wizard Rendering

This library can also be used to render a form wizard within your application using the same method as rendering a form. The determiniation on whether it should render as a wizard or not is based on the display property of the form schema being set to wizard.

<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
    <script src="https://cdn.form.io/js/formio.embed.js"></script>
  </head>
  <body>
    <div id='formio'></div>
    <script type='text/javascript'>
      Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/wizard');
    </script>
  </body>
</html>

Form Embedding

You can also use this library as a JavaScript embedding of the form using a single line of code. For example, to embed the https://examples.form.io/example form within your application you can simply use the following embed code.

<script src="https://cdn.form.io/js/formio.embed.min.js?src=https://examples.form.io/example&libs=true"></script>

For an example of how this looks and works, check out the following Form.io Inline Embedding

Form Embedding Documentation

For a more complete documentation of how to embed forms, go to the Form Embedding Documentation.

JavaScript SDK

In addition to having a Form Renderer within this application, you can also use this library as a JavaScript SDK in your application. For example, to load a Form, and then submit that form you could do the following within your JavaScript.

<html>
  <head>
    <script src='https://cdn.form.io/js/formio.min.js'></script>
    <script type='text/javascript'>
      var formio = new Formio('https://examples.form.io/example');
      formio.loadForm().then(function(form) {
      
        // Log the form schema.
        console.log(form);
        
        formio.saveSubmission({data: {
          firstName: 'Joe',
          lastName: 'Smith',
          email: 'joe@example.com'
        }}).then(function(submission) {
        
          // Log the full submission object.
          console.log(submission);
        });
      });
    </script>
  </head>
</html>

You can also use this within an ES6 application as follows.

import { Formio } from '@formio/js/sdk';
let formio = new Formio('https://examples.form.io/example');
formio.loadForm((form) => {
  console.log(form);
  formio.saveSubmission({data: {
    firstName: 'Joe',
    lastName: 'Smith',
    email: 'joe@example.com'
  }}).then((submission) => {
    console.log(submission);
  });
});

JavaScript SDK Documentation.

For more complete documentation over the JavaScript SDK, please take a look at the JavaScript SDK Documentation.

Full Developer API Documentation

To view the full SDK Documentation, go to Developer SDK Documentation

NPM DownloadsLast 30 Days