JavaScript powered Forms with JSON Form Builder
npm install finomial-formiojs
npm install --save formiojs
`
Form Building
This library has a very powerful JSON form builder, and can be used like the following.
`html
`
This will create a robust Form builder embedded right within your own application. See Our Demo Page for an example.
Form Rendering
The following is a simple example on how to render a form within your HTML application.
`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.
`js
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
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/v38du9y1/
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
`
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.
`html
`
For an example of how this looks and works, check out the following Form.io Form Embedding CodePen
Full Form Renderer Documentation
For a more complete documentation of how to utilize this library within your application go to the Form Renderer documentation within the Wiki
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
`
You can also use this within an ES6 application as follows.
`js
import Formio from 'formiojs';
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);
});
});
``