GithubHelp home page GithubHelp logo

laakarihinta / formio.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from formio/formio.js

0.0 6.0 0.0 20.4 MB

JavaScript powered forms and SDK for https://form.io

Home Page: https://formio.github.io/formio.js

License: MIT License

JavaScript 99.21% CSS 0.79%

formio.js's Introduction

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
  • 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 formiojs

Simple Example

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

<html>
  <head>
    <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
    <link rel='stylesheet' href='https://unpkg.com/formiojs@latest/dist/formio.full.min.css'>
    <script src='https://unpkg.com/formiojs@latest/dist/formio.full.min.js'></script>
    <script type='text/javascript'>
      window.onload = function() {
        Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/example');
      };
    </script>
  </head>
  <body>
    <div id='formio'></div>
  </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.

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://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
    <link rel='stylesheet' href='https://unpkg.com/formiojs@latest/dist/formio.full.min.css'>
    <script src='https://unpkg.com/formiojs@latest/dist/formio.full.min.js'></script>
    <script type='text/javascript'>
      window.onload = function() {
        Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/wizard');
      };
    </script>
  </head>
  <body>
    <div id='formio'></div>
  </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://unpkg.com/formiojs@latest/dist/formio.embed.min.js?src=https://examples.form.io/example"></script>

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>
  <head>
    <script src='https://unpkg.com/formiojs@latest/dist/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: '[email protected]'
        }}).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 'formiojs';
let formio = new Formio('https://examples.form.io/example');
formio.loadForm((form) => {
  console.log(form);
  formio.saveSubmission({data: {
    firstName: 'Joe',
    lastName: 'Smith',
    email: '[email protected]'
  }}).then((submission) => {
    console.log(submission);
  });
});

JavaScript SDK Documentation.

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

Full Developer API Documentation

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

formio.js's People

Contributors

douglaselee avatar edenware avatar guillaumesmaha avatar manishkumar-tudip avatar neolanders avatar rahatarmanahmed avatar randallknutson avatar travist avatar yuryrybaksoftensity avatar zackurben avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.