• Stars
    star
    301
  • Rank 138,451 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSON powered forms for React.js

React Formio

A React library for rendering out forms based on the Form.io platform.

Example Application

To see an example application of how to implement all the components and modules in this library, see https://github.com/formio/react-app-starterkit

Install

npm

@formio/react can be used on the server, or bundled for the client using an npm-compatible packaging system such as Browserify or webpack.

npm install @formio/react --save
npm install formiojs --save // Install formiojs since it is a peerDependency

Components

Form

The form component is the primary component of the system. It is what takes the form definition (json) and renders the form into html. There are multiple ways to send the form to the Form component. The two main ways are to pass the src prop with a url to the form definition, usually a form.io server. The other is to pass the form prop with the json definition and optionally a url prop with the location of the form.

Props

Name Type Default Description
src url The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well.
url url The url of the form definition. The form will not be loaded from this url and the submission will not be saved here either. This is used for file upload, oauth and other components or actions that need to know where the server is. Use this in connection with form .
form object Instead of loading a form from the src url, you can preload the form definition and pass it in with the form prop. You should also set url if you are using any advanced components like file upload or oauth.
submission object Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form.
options object An options object that can pass options to the formio.js Form that is rendered. You can set options such as readOnly, noAlerts or hide. There are many options to be found in the formio.js library.

Event Props

You can respond to various events in the form. Simply pass in a prop with a function for one of these events.

Name Parameters Description
onSubmit submission: object When the submit button is pressed and the submission has started. If src is not provided, this will be the final submit event.
onSubmitDone submission: object When the submission has successfully been made to the server. This will only fire if src is set.
onChange submission: object, submission.changed: object of what changed, submission.isValid: boolean - if the submission passes validations. A value in the submission has changed.
onError errors: array or string or boolean Called when an error occurs during submission such as a validation issue.
onRender Triggers when the form is finished rendering.
onCustomEvent { type: string - event type, component: object - triggering component, data: object - data for component, event: string - raw event } Event that is triggered from a button configured with "Event" type.
onPrevPage { page: integer - new page number, submission: object - submission data } Triggered for wizards when "Previous" button is pressed.
onNextPage { page: integer - new page number, submission: object - submission data } Triggered for wizards when "Next" button is pressed.
formReady formInstance: Webform/Wizard - form class instance Called when the form gets ready state.

Example

Give Form a src property and render:

import React from 'react';
import ReactDOM from 'react-dom';
import {Form} from '@formio/react';
ReactDOM.render(
  <Form src="https://example.form.io/example" onSubmit={console.log} />
  , document.getElementById('example')
);

FormBuilder

The FormBuilder class can be used to embed a form builder directly in your react application. Please note that you'll need to include the CSS for the form builder from formio.js as well.

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

Without Components:

<FormBuilder form={[]}/>

With Components:

<FormBuilder form={{
 display: 'form',
 components: [
 {
   "label": "Email",
   "tableView": true,
   "key": "email",
   "type": "email",
   "input": true
 },
 {
   "label": "Password",
   "tableView": false,
   "key": "password",
   "type": "password",
   "input": true,
   "protected": true
 },
 ]
 }}/>

Please note that the FormBuilder component does not load and save from/to a url. You must handle the form definition loading and saving yourself or use the FormEdit component.

Props

Name Type Default Description
form object This is the form definition object. It should at least have a display property set to form, wizard or pdf.
options object an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library.

Event Props

Name Parameters Description
onChange schema: object Triggered any time the form definition changes.
onEditComponent component: object Triggered when the component settings dialog is opened.
onSaveComponent component: object Triggered when the component settings dialog is saved and closed.
onCancelComponent component: object Triggered when the component settings dialog is cancelled.
onDeleteComponent component: object Triggered when a component is removed from the form.
onUpdateComponent component: object Triggered when a component is added or moved in the form.

Example

import React from 'react';
import ReactDOM from 'react-dom';
import {FormBuilder} from '@formio/react';
ReactDOM.render(
  <FormBuilder form={{display: 'form'}} onChange={(schema) => console.log(schema)} />
  , document.getElementById('builder')
);

Errors

The Errors component can be used to print out errors that can be generated within an application. It can handle many types of errors that are generated by the form.io actions.

Props

Name Type Default Description
errors any null If null is passed, the component is not rendered. Otherwise it will render the errors. There are various formats (including an array of errors) that can be passed in.
type string 'danger' The bootstrap alert type to render the container.

Event Props

None

FormEdit

The FormEdit component wraps the FormBuilder component and adds the title, display, name and path fields at the top along with a save button.

Props

Name Type Default Description
form object {display: 'form' | 'wizard'} The form definition of the exiting form that is to be modified.
options object {} The options to be passed to FormBuilder.
saveText string '' The string that will be displayed in the save-button.

Event Props

Name Parameters Description
saveForm form Called when the save button is pressed. Will pass the form definition to the callback.

FormGrid

The FormGrid component can be used to render a list of forms with buttons to edit, view, delete, etc on each row.

Props

Name Type Default Description
forms array of forms [] A list of forms to be rendered in the grid.
perms object {view: true, edit: truem data: true, delete: true} Whether or not to display buttons on the grid.
query object {} A query filter for passing to getForms when fetching forms.
getForms function () => {} A function to trigger getting a new set of forms. Should accept the page number and filter query object as parameters.

Event Props

Name Parameters Description
onAction form: object, action: string Called when the user clicks on a button on a row of the form.

SubmissionGrid

The submisison grid will render a list of submissions and allow clicking on one row to select it.

Props

Name Type Default Description
submissions array of submissions [] A list of submissions to be rendered in the grid.
query object {} A query filter for passing to getForms when fetching submissions.
form object {} The form definition for the submissions. This is used to render the submissions.
getSubmissions function () => {} A function to trigger getting a new set of submissions. Should accept the page number and filter query object as parameters.

Event Props

Name Parameters Description
onAction submission: object, action: string Called when the user clicks on a button on a row of the submission.

Modules

Modules contain Redux actions, reducers, constants and selectors to simplify the API requests made for form.io forms. Reducers, actions and selectors all have names. This provides namespaces so the same actions and reducers can be re-used within the same redux state.

root

The root module is the container for things shared by other modules such as the selectRoot selector.

Selectors

Name Parameters Description
selectRoot name: string, state: object Returns the state for a namespace.
selectError name: string, state: object Returns any errors for a namespace.
selectIsActive name: string, state: object Returns isActive state for a namespace.

auth

The auth module is designed to make it easier to login, register and authenticate users within react using the form.io login system.

Reducers

Name Parameters Description
auth config: object Mounts the user and access information to the state tree. Config is not currently used but is a placeholder to make it consistent to the other reducers.

Actions

Name Parameters Description
initAuth This is usually used at the start of an app code. It will check the localStorage for an existing user token and if found, log them in and fetch the needed information about the user.
setUser user: object When a user logs in, this will set the user and fetch the access information for that user. The user object is usually a submission from the login or register form.
logout This action will reset everything to the default state, including removing any localStorage information.

form

The form module is for interacting with a single form.

Reducers

Name Parameters Description
form config: object Mounts the form to the state tree. The config object should contain a name property defining a unique name for the redux state.

Actions

Name Parameters Description
getForm name: string, id: string, done: function Fetch a form from the server. If no id is provided, the name is used as the path. The done callback will be called when the action is complete. The first parameter is any errors and the second is the form definition.
saveForm name: string, form: object, done: function Save a form to the server. It will use the _id property on the form to save it if it exists. Otherwise it will create a new form. The done callback will be called when the action is complete. The first parameter is any errors and the second is the form definition.
deleteForm name: string, id: string, done: function Delete the form on the server with the id.
resetForm Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well.

Selectors

Name Parameters Description
selectForm name: string, state: object Select the form definition from the state.

forms

The forms module handles multiple forms like a list of forms.

Reducers

Name Parameters Description
forms config: object Mounts the forms to the state tree. The config object should contain a name property defining a unique name for the redux state. The config object can also contain a query property which is added to all requests for forms. For example: {tags: 'common'} would limit the lists of forms to only forms tagged with 'common'.

Actions

Name Parameters Description
getForms name: string, page: integer, params: object Fetch a list of forms from the server. params is a query object to filter the forms.
resetForms Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well.

Selectors

Name Parameters Description
selectForms name: string, state: object Select the list of forms from the state.

submission

The submission module is for interacting with a single submission.

Reducers

Name Parameters Description
submission config: object Mounts the submission to the state tree. The config object should contain a name property defining a unique name for the redux state.

Actions

Name Parameters Description
getSubmission name: string, id: string, formId: string, done: function Fetch a submission from the server. The done callback will be called when the action is complete. The first parameter is any errors and the second is the submission.
saveSubmission name: string, submission: object, formId: string, done: function Save a submission to the server. It will use the _id property on the submission to save it if it exists. Otherwise it will create a new submission. The done callback will be called when the action is complete. The first parameter is any errors and the second is the submission.
deleteSubmission name: string, id: string, formId: string, done: function Delete the submission on the server with the id.
resetSubmission Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well.

Selectors

Name Parameters Description
selectSubmission name: string, state: object Select the submission data from the state.

submissions

The submissions module handles multiple submissions within a form, like for a list of submissions.

Reducers

Name Parameters Description
submissions config: object Mounts the submissions to the state tree. The config object should contain a name property defining a unique name for the redux state.

Actions

Name Parameters Description
getSubmissions name: string, page: integer, params: object, formId: string Fetch a list of submissions from the server. params is a query object to filter the submissions.
resetSubmissions Reset this reducer back to its initial state. This is automatically called after delete but can be called other times as well.

Selectors

Name Parameters Description
selectSubmissions name: string, state: object Select the list of submissions from the state.

License

Released under the MIT License.

More Repositories

1

formio

A Form and Data Management Platform for Progressive Web Applications.
JavaScript
2,005
star
2

formio.js

JavaScript powered Forms with JSON Form Builder
JavaScript
1,838
star
3

angular

JSON powered forms for Angular
TypeScript
634
star
4

ngFormBuilder

The Form.IO Form Builder Application
JavaScript
130
star
5

resquel

Easily convert your SQL database into a REST API using Express.js
TypeScript
121
star
6

vue

Javascript Powered forms and JSON form builder for Vue.js
TypeScript
118
star
7

ngFormio

JSON powered form rendering library for AngularJS + Form.io.
JavaScript
99
star
8

angular-demo

A Demo application with Angular + Form.io
TypeScript
62
star
9

react-app-starterkit

A react starterkit for creating new web applications with Form.io
TypeScript
56
star
10

aurelia-formio

Form.io JSON Forms and Form Builder for Aurelia
TypeScript
45
star
11

angular-material

JSON powered forms for Angular Material
TypeScript
45
star
12

help.form.io

The help site for Form.io
JavaScript
42
star
13

angular-app-starterkit

Angular 7 + Bootstrap 4 application starter kit using Form.io
TypeScript
40
star
14

formio-viewer

Landing page viewer for forms and wizards within Form.io
HTML
33
star
15

keycred

A key credential generator for Office 365 App-Only API applications.
JavaScript
20
star
16

contrib

Contributed components for Form.io
HTML
18
star
17

react-native-formio

React Native Version of Formio Renderer
JavaScript
18
star
18

formio-service

The Form.IO API Service library for Node.js applications
JavaScript
18
star
19

cli

The Form.io command line interface.
JavaScript
17
star
20

formio-php

PHP Integration with Form.io
PHP
13
star
21

vue-app-starterkit

Starterkit for building apps with form.io and vue
Vue
13
star
22

formio-webhook-receiver

An example webhook receiver application.
JavaScript
13
star
23

formio-app-formio

The Form.io main front-end application.
JavaScript
13
star
24

formio-app-servicetracker

JavaScript
11
star
25

ngFormioGrid

Provides a way to display Form.io submission data within the Angular UI-Grid.
JavaScript
11
star
26

uswds

JavaScript Powered Forms for the United States Web Design System
JavaScript
11
star
27

formio-app-basic

A basic starter Angular.js application with User Authentication using Form.io
JavaScript
9
star
28

formio-red

Form.io integration into Node Red - http://nodered.org
HTML
9
star
29

enterprise-release

Release notes for Enterprise Form.io Servers
9
star
30

formio-upload

A file upload server/proxy for use with the Form.io file component.
JavaScript
9
star
31

core

The Form.io Core Javascript Framework
TypeScript
9
star
32

formio-app-formbuilder

A user portal for creating and managing forms
JavaScript
8
star
33

bootstrap

Bootstrap templates for form.io forms
JavaScript
7
star
34

formio-wizard

Angular.js Wizard using Form.io forms.
JavaScript
7
star
35

sw-express

Extend express so it will work in service workers
JavaScript
6
star
36

ng-app-starterkit

An angular 1.x starterkit for creating new web applications with Form.io
JavaScript
6
star
37

ngFormioHelper

A library to help build Angluar.js applications on top of Form.io.
JavaScript
6
star
38

examples.form.io

Examples of Form.IO integration and implementation.
JavaScript
6
star
39

formio-app-gpstracker

An application that allows you to create trails and track GPS coordinates.
JavaScript
5
star
40

formio-app-humanresources

An form and data management application for Human Resources.
JavaScript
5
star
41

formio-workers

A library of workers for the Form.io platform.
JavaScript
5
star
42

formio-server-proxy

A proxy server for the Form.io Enterprise Server.
JavaScript
5
star
43

formio-app-eventmanager

A very basic Event Registration system built on top of Form.io.
JavaScript
5
star
44

formio-app-todo

An example ToDo application for Form.io.
JavaScript
5
star
45

formio-app-movie

An example application using the Form.IO platform.
JavaScript
4
star
46

api

A form manager module
TypeScript
4
star
47

pdf-enterprise

PDF Server for Form.io Enterprise Server
CSS
4
star
48

aws-formio-deployment

Configurations for deploying Form.io into AWS
Roff
4
star
49

edge

A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.
JavaScript
4
star
50

pdf-libs

The PDF Libraries
C++
3
star
51

cordova-offline-demo

Cordova Offline Application Demo
JavaScript
3
star
52

uswds-viewer

HTML
3
star
53

semantic

Semantic UI Templates for form.io
JavaScript
3
star
54

module-example

An example of how to create a module for the formio.js renderer and builder.
JavaScript
3
star
55

deploy

Deployment strategies for Form.io Enterprise platform
Smarty
3
star
56

generator-formio

A Yeoman Generator for creating Form.IO applications.
JavaScript
3
star
57

bulma

Bulma templates for formio.js
JavaScript
2
star
58

formio-question

A directive that provides question and answer capabilities for Form.io forms.
JavaScript
2
star
59

formio-app-salesquote

An example application in Form.io for managing sales quotes.
JavaScript
2
star
60

instructions

Instructions for using the private package repository
2
star
61

eventmanager

An Event Manager application built in Angular + Form.io
TypeScript
2
star
62

formio-translations-demo

An Angular 5 application that integrates PhraseApp with Form.io
TypeScript
2
star
63

portal

The Form.io Community Edition Portal
TypeScript
2
star
64

aurelia-app-starterkit

HTML
2
star
65

react-native-app

Makefile
1
star
66

pretty-checkbox

Adding pretty-checkbox plugin to Form.io forms
JavaScript
1
star
67

custom-renderer

An example custom renderer that extends the Form.io core renderer.
JavaScript
1
star
68

eslint-config-formio

The ESLint config for Form.io projects
JavaScript
1
star
69

formio-form

A basic Form.IO form template
HTML
1
star
70

lodash

A tiny (3kb gzipped) reduced-set implementation of the Lodash library.
JavaScript
1
star