New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-formation

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-formation

[![Build Status](https://travis-ci.org/k88hudson/react-formation.svg)](https://travis-ci.org/k88hudson/react-formation) [![Coverage Status](https://coveralls.io/repos/k88hudson/react-formation/badge.svg?branch=master&service=github)](https://coveralls.io/

latest
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

Get started with React Formation

Build Status Coverage Status

Install

You can install React Formation from npm by running npm install react-formation. If you are using common js, you can require it like this:

var Formation = require('react-formation');

Create a Form

First, let's define the structure of your form. You can do that by using CreateForm just like how you would use React.createClass, including a render function:

var Formation = require('react-formation');

var Form = Formation.CreateForm({
  render: function () {
    return (<form>

      <label>Name</label>
      <input type="text" name="name" />

      <label>Email</label>
      <input type="text" name="email" />

      <button>Submit</button>

    </form>);
  }
});

Next, add a getSchema method that returns a schema defining all the fields in the form, and link corresponding inputs with this.linkField:

var Form = Formation.CreateForm({

  getSchema: function () {
    return {
      name: {required: true}
      email: {validations: 'email'}
    };
  },

  render: function () {
    return (<form>

      <label>Name</label>
      <input type="text" valueLink={this.linkField('name')} />

      <label>Email</label>
      <input type="text" valueLink={this.linkField('email')} />

      <button>Submit</button>

    </form>);
  }

});

Finally, add an onSuccess callback that gets called on a successful submit, and add this.submitForm as a callback to any submit buttons.

var Form = Formation.CreateForm({

  getSchema: function () {
    return {
      name: {required: true}
      email: {validations: 'email'}
    };
  },

  onSuccess: function (data) {
    console.log(data);
  },

  render: function () {
    return (<form>

      <label>Name</label>
      <input type="text" valueLink={this.linkField('name')} />

      <label>Email</label>
      <input type="text" valueLink={this.linkField('email')} />

      <button onClick={this.submitForm}>Submit</button>

    </form>);
  }

});

Rendering a Form

You can use your new Form class just like you would any other React element, including passing props. For example, if you wanted to render it directly into document.body:

React.render(<Form />, document.body);

More

Check out the guide and examples:

FAQs

Package last updated on 29 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts