Convert Figma logo to code with AI

surveyjs logosurvey-library

SurveyJS is an open-source JavaScript form builder library that allows developers to create dynamic forms, multi-step form wizards, and survey applications. It supports React, Angular, and Vue.js (Vue 3), and can also be used in applications built with plain JavaScript.

4,795
912
4,795
483

Top Related Projects

Embeddable JSON form builder for React, Angular, Vue, and plain JavaScript. Drag-and-drop UI, your backend.

JavaScript powered Forms with JSON Form Builder

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

34,331

Build forms in React, without the tears 😭

A jQuery plugin for drag and drop form creation

Quick Overview

SurveyJS is an open-source JavaScript library for building feature-rich surveys and forms. It provides a powerful set of tools for creating, customizing, and managing surveys, with support for various question types, conditional logic, and data validation.

Pros

  • Extensive customization options for survey appearance and behavior
  • Support for a wide range of question types and complex logic
  • Cross-platform compatibility (works with popular frameworks like React, Vue, and Angular)
  • Active development and community support

Cons

  • Steep learning curve for advanced features
  • Large file size may impact page load times
  • Some advanced features require a commercial license
  • Documentation can be overwhelming for beginners

Code Examples

Creating a simple survey:

const surveyJson = {
  elements: [{
    name: "FirstName",
    title: "Enter your first name:",
    type: "text"
  }, {
    name: "DoYouLikeIt",
    title: "Do you like SurveyJS?",
    type: "radiogroup",
    choices: ["Yes", "No"]
  }]
};

const survey = new Survey.Model(surveyJson);

Adding a custom widget:

Survey.CustomWidgetCollection.Instance.addCustomWidget({
  name: "rating",
  title: "Rating",
  widgetIsLoaded: function() {
    return typeof $ === "function" && !!$.fn.barrating;
  },
  isFit: function(question) {
    return question.getType() === "rating";
  },
  htmlTemplate: "<select></select>",
  afterRender: function(question, el) {
    var $el = $(el).is("select") ? $(el) : $(el).find("select");
    $el.barrating("show", {
      theme: "css-stars",
      initialRating: question.value,
      onSelect: function(value, text) {
        question.value = value;
      }
    });
  }
});

Implementing conditional logic:

const surveyJson = {
  elements: [{
    type: "radiogroup",
    name: "haveCar",
    title: "Do you have a car?",
    choices: ["Yes", "No"]
  }, {
    type: "text",
    name: "carType",
    title: "What car do you have?",
    visibleIf: "{haveCar} = 'Yes'"
  }]
};

Getting Started

  1. Install SurveyJS:

    npm install survey-knockout survey-core
    
  2. Import and create a survey:

    import { Model } from 'survey-core';
    import 'survey-core/defaultV2.min.css';
    
    const surveyJson = {
      elements: [{
        name: "Name",
        title: "Your name:",
        type: "text"
      }]
    };
    
    const survey = new Model(surveyJson);
    
  3. Render the survey:

    survey.onComplete.add((sender, options) => {
      console.log(JSON.stringify(sender.data, null, 3));
    });
    
    const app = document.getElementById("surveyElement");
    survey.render(app);
    

Competitor Comparisons

Embeddable JSON form builder for React, Angular, Vue, and plain JavaScript. Drag-and-drop UI, your backend.

Pros of survey-creator

  • Provides a visual interface for creating surveys, making it more user-friendly for non-technical users
  • Offers drag-and-drop functionality for easy question arrangement and survey design
  • Includes built-in preview and testing features for immediate survey validation

Cons of survey-creator

  • Larger file size and potentially higher resource usage due to additional UI components
  • May have a steeper learning curve for developers who prefer working directly with code
  • Less flexibility for custom implementations compared to the core library

Code Comparison

survey-library:

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

survey-creator:

const creator = new SurveyCreator.SurveyCreator({
  showLogicTab: true,
  isAutoSave: true
});
creator.saveSurveyFunc = (saveNo, callback) => {
  // Custom save logic
};

The survey-library code focuses on defining survey structure programmatically, while survey-creator provides a more abstracted approach with built-in functionality for survey editing and management.

JavaScript powered Forms with JSON Form Builder

Pros of formio.js

  • More flexible and customizable, allowing for complex form structures
  • Better integration with server-side components and APIs
  • Supports a wider range of form elements and input types

Cons of formio.js

  • Steeper learning curve due to its complexity
  • Larger file size, which may impact load times
  • Less intuitive for simple survey creation

Code Comparison

formio.js:

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

survey-library:

const survey = new Survey.Model({
  questions: [
    {
      name: "firstName",
      title: "First Name",
      type: "text"
    },
    {
      name: "lastName",
      title: "Last Name",
      type: "text"
    }
  ]
});

Both libraries offer powerful form-building capabilities, but formio.js provides more advanced features at the cost of complexity, while survey-library focuses on simplicity and ease of use for survey creation.

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 framework with built-in CRUD operations
  • Extensive ecosystem of components and add-ons
  • Better suited for complex data management tasks

Cons of react-admin

  • Steeper learning curve due to its extensive feature set
  • Less flexible for non-admin or custom UI scenarios
  • Potentially heavier bundle size for simpler applications

Code Comparison

react-admin:

import { Admin, Resource, ListGuesser } from 'react-admin';
import { dataProvider } from './dataProvider';

const App = () => (
  <Admin dataProvider={dataProvider}>
    <Resource name="users" list={ListGuesser} />
  </Admin>
);

survey-library:

import { Model } from 'survey-core';

const surveyJson = {
  elements: [{ type: "text", name: "firstName", title: "Enter your name:" }]
};
const survey = new Model(surveyJson);

Key Differences

  • react-admin focuses on building admin interfaces with data management
  • survey-library specializes in creating dynamic surveys and forms
  • react-admin provides a full-featured framework, while survey-library offers more flexibility for survey-specific use cases

Both libraries serve different purposes, with react-admin being more suitable for complex admin panels and survey-library excelling in survey and form creation scenarios.

34,331

Build forms in React, without the tears 😭

Pros of Formik

  • Lightweight and focused on React form management
  • Seamless integration with React ecosystem and state management
  • Extensive documentation and community support

Cons of Formik

  • Limited to React applications, not suitable for other frameworks
  • Requires additional libraries for advanced form features
  • Less out-of-the-box functionality compared to Survey Library

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>

Survey Library:

import * as Survey from 'survey-react';

const json = {
  questions: [{ type: 'text', name: 'name', title: 'Your name:' }]
};
<Survey.Survey json={json} onComplete={handleSubmit} />;

Summary

Formik is a lightweight, React-specific form management library with excellent React integration. It's ideal for developers who need fine-grained control over form behavior in React applications. However, it may require additional libraries for complex form scenarios.

Survey Library offers a more comprehensive solution for creating surveys and complex forms across different frameworks. It provides more out-of-the-box functionality but may be overkill for simple form needs in React applications.

Choose Formik for React-specific, customizable form management, and Survey Library for cross-framework, feature-rich survey creation.

A jQuery plugin for drag and drop form creation

Pros of formBuilder

  • Lightweight and easy to integrate
  • Customizable UI with drag-and-drop functionality
  • Extensive documentation and examples

Cons of formBuilder

  • Limited advanced features compared to survey-library
  • Smaller community and fewer third-party integrations
  • Less frequent updates and maintenance

Code Comparison

formBuilder:

$(document).ready(function() {
  $('#fb-editor').formBuilder();
});

survey-library:

const survey = new Survey.Model(json);
$("#surveyContainer").Survey({
    model: survey
});

Both libraries offer simple initialization, but survey-library provides more configuration options out of the box. formBuilder focuses on a user-friendly drag-and-drop interface, while survey-library offers a more comprehensive set of features for complex surveys and data collection.

formBuilder is ideal for projects requiring quick form creation with minimal setup, whereas survey-library is better suited for advanced survey applications with extensive customization needs. The choice between the two depends on the specific requirements of your project, such as the complexity of forms, desired features, and integration capabilities.

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

banner_form_library

Build Status Software License Tested with Playwright Issues Closed issues GitHub Release

SurveyJS Form Library

SurveyJS Form Library is a free and open-source JavaScript form library for rendering dynamic, JSON-based forms and surveys in React, Angular, Vue, and plain JavaScript applications. It collects responses in the browser and lets you send submitted data to any backend or database.

Use it to build complex multi-step forms, pop-up surveys, quizzes, scored surveys, calculator forms, and other data-entry tools. Form content and structure, validation, conditional logic, navigation, and appearance are defined through a SurveyJS JSON form definition.

You can create form definitions manually, generate them with AI, or build them visually with SurveyJS Creator, an embeddable drag-and-drop form builder.


Documentation · Setup Guides for My Stack · Form Library Demos · Theme Adapters · Store Survey Results · Report Bug


https://github.com/surveyjs/survey-library/assets/102306951/844563b2-c7c3-400c-962f-bcdbe7274d55

How It Works

SurveyJS Form Library renders forms from JSON definitions directly in your web application. It runs in the browser and does not require a SurveyJS backend, so you retain control over form definitions, submitted responses, and data storage.

Your application can:

  1. Create or load a SurveyJS JSON form definition.
  2. Render it with SurveyJS Form Library.
  3. Collect responses in the browser.
  4. Send submitted data to your backend.
  5. Store it in the database or service of your choice.

Installation

Choose the package for your framework:

React Form Library

npm install survey-react-ui

Get Started with Form Library for React

Angular Form Library

npm install survey-angular-ui

Get Started with Form Library for Angular

Vue.js Form Library

npm install survey-vue3-ui

Get Started with Form Library for Vue.js

Plain JavaScript Form Library

npm install survey-js-ui

Get Started with Form Library for Plain JavaScript

Package Architecture

SurveyJS Form Library separates form logic from rendering. The framework-independent survey-core package provides the form model, validation, conditional logic, calculations, navigation, localization, and other core behavior. Framework-specific packages such as survey-react-ui, survey-angular-ui, and survey-vue3-ui render that model in React, Angular, and Vue 3 applications. Installing a rendering package brings survey-core with it.

Key Features

Dynamic Forms and Surveys

  • Multi-step forms, quizzes, scored surveys, calculator forms, and survey pop-ups
  • Conditional visibility, branching, calculated values, and expression-based logic
  • Input validation, partial submissions, auto-save, and lazy loading
  • Dynamic panels, repeating question groups, carry-forward responses, and text piping
  • Multiple navigation modes for long and complex forms

Multi-Framework Support

  • Dedicated Form Library rendering packages for React, Angular, Vue 3, and plain JavaScript
  • TypeScript support
  • Client-side rendering with no required SurveyJS backend

Data and Backend Integration

Form Controls

Localization and Accessibility

  • Community-supported localization for 50+ languages
  • Multi-language forms and automatic locale selection
  • Right-to-left language support
  • Accessible input controls and keyboard navigation

Appearance and UI Customization

  • Shared design token system based on CSS variables
  • Built-in themes with support for custom branding
  • Theme Adapters for Bootstrap, Material UI, and shadcn/ui
  • Custom question rendering and reusable UI components
  • Configurable layouts, navigation controls, validation messages, and form behavior

Resources

SurveyJS Product Family

  • Form Library - A free and open-source MIT-licensed JavaScript library that renders dynamic JSON-based forms in your web application, and collects responses.
  • Survey Creator - An embeddable drag-and-drop form builder that generates SurveyJS JSON form definitions. Try out a free full-featured demo to evaluate its capabilities.
  • Dashboard - Simplifies survey data visualization and analysis with interactive and customizable charts and tables.
  • PDF Generator - Renders SurveyJS surveys and forms as PDF files in a browser. Save custom forms to PDF (both editable and read-only).
  • AI Form Response Extractor - A free and open-source MIT-licensed JavaScript library that extracts responses from paper forms, PDFs, and images, maps them to the SurveyJS schema, and produces a unified response object that can be stored and processed alongside online submissions. (ai-form-response-extractor).

Build from Source

  1. Build the platform-independent part

  2. Build one of the UI packages

Licensing

SurveyJS Form Library is distributed under the MIT license.

NPM DownloadsLast 30 Days