1.4.3 • Published 6 years ago

fl-form-builder v1.4.3

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

fl-form-builder

Build Status npm Downloads GitHub license

A JS form builder inspired by Google Forms.

Usage demo

Getting started

Creating a form-builder

Just load the javascript and the CSS and call new FormBuilder(container), using the FormBuilder global object.

<!-- RequireJS -->
<link rel="stylesheet" href="../dist/fl-form-builder.css">
<script src="../dist/fl-form-builder.js"></script>

<div class="form-builder-container"></div>

<script>
  var container = document.querySelector('.form-builder-container');
  const formBuilder = new FormBuilder(container);
</script>

Saving the form state

To save the created form just store the object – or a serialization of it – returned by formBuilder.exportState().

  // exporting
  const state = formBuilder.exportState();

Restoring a form state

If you want to get the form-builder back to the way it was when the user last used it, you can just import the state you saved with the importState method. You could, for example, do that when the form loads.

  // importing
  const formBuilder = new FormBuilder(container);
  formBuilder.importState(state);

Plugins

You can add custom field types. They must follow this react signature:

  const FieldCreatorPropType = {
    info: React.PropTypes.shape({
      type: React.PropTypes.string,
      group: React.PropTypes.string,
      displayName: React.PropTypes.string,
    }),
    initialState: React.PropTypes.shape({
      type: React.PropTypes.string,
      group: React.PropTypes.string,
      displayName: React.PropTypes.string,

      required: React.PropTypes.bool,
      configShowing: React.PropTypes.bool,
    }),
    RenderEditor: React.PropTypes.func, // React render function
  };

To add your plugins just send them in an array at instantiation time.

  const formBuilder = new FormBuilder(container. [CustomPlugin1, CustomPlugin1]);
1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago