survey-library
Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
Top Related Projects
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
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
-
Install SurveyJS:
npm install survey-knockout survey-core
-
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);
-
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
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.
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
SurveyJS Form Library is a free to use MIT-licensed client-side component that allows you to render dynamic JSON-based forms in any JavaScript application, collect responses, and send all form submission data to a database of your choice. You can use it for multi-page forms of any length and complexity, pop-up surveys, quizzes, scored surveys, calculator forms, and more. SurveyJS Form Library has native support for React, Angular, Vue, and Knockout; jQuery is supported via a wrapper over the Knockout version. The library interacts with the server using JSON objects—for both form metadata, also known as form JSON schemas, and results. The SurveyJS product family also includes a robust form builder library that automatically generates form configuration files in JSON format. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
Documentation · Roadmap · View Demos · Generate JSON form · Report Bug · Twitter
https://github.com/surveyjs/survey-library/assets/102306951/844563b2-c7c3-400c-962f-bcdbe7274d55
Features
- It's suitable for multi-page forms, quizzes, scored surveys, calculator forms, and survey pop-ups
- Integration with React, Angular, Vue, jQuery, and Knockout
- Compatible with any server & database
- Integration examples for PHP, ASP.NET Core, and NodeJS
- All data is stored on your own servers; therefore, there are no limits on the number of forms, submissions, and file uploads
- 20+ accessible input types, panels for question grouping, dynamic questions with a duplicate group option
- Input validation, partial submits & auto-save, lazy loading, load choices from web services
- Custom input fields
- Carry forward responses, text piping, autocomplete
- Integration with 3rd-party libraries and payment systems
- Support for webhooks
- Expression language (Built-in & Custom Functions), data aggregation within a form
- TypeScript support
- Auto-localization and multi-locale surveys, support for RTL languages
- Weekly updates
- 120+ starter demos & tutorials
- Community-supported UI localization to 50+ languages
- Built-in themes and CSS customization
- e-Signature field
- Image capture
- All popular types of form navigation
Get Started
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 - A self-hosted drag-and-drop form builder that automatically generates JSON definition (schemas) of your forms in real time. 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 - An open-source JavaScript library that renders SurveyJS surveys and forms as PDF files in a browser. With PDF Generator you can save an unlimited number of custom-built forms to PDF (both editable and read-only).
Build the SurveyJS Form Library from Sources
The instructions below apply to SurveyJS Form Library for React, Knockout, jQuery, and Vue 2. If you are looking for instructions on how to build the library for Angular or Vue 3, refer to README files within the
survey-angular-ui
orsurvey-vue3-ui
packages.
-
Clone the repo
git clone https://github.com/surveyjs/survey-library.git cd survey-library
-
Install dependencies
Make sure that you have Node.js v14 or later and a compatible npm version installed.npm install -g karma-cli npm install
-
Build the platform-independent part and plugins
npm run build_core npm run build-plugins
-
Build the library
npm run build
You can find the built scripts and style sheets in folders under the
build
directory. -
Run test examples
npm run serve
This command runs a local HTTP server at http://localhost:7777/.
-
Run unit tests
npm run test
The unit tests use Karma.
Licensing
SurveyJS Form Library is distributed under the MIT license.
Top Related Projects
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
Build forms in React, without the tears 😭
A jQuery plugin for drag and drop form creation
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot