All Projects → insin → Newforms

insin / Newforms

Licence: other
Isomorphic form-handling for React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Newforms

web-forward
DEPRECATED - Innovation acceleration program from Mozilla Labs
Stars: ✭ 17 (-97.38%)
Mutual labels:  unmaintained
Rust Os Comparison
A comparison of operating systems written in Rust
Stars: ✭ 292 (-55.01%)
Mutual labels:  unmaintained
Msx
JSX for Mithril.js 0.x
Stars: ✭ 370 (-42.99%)
Mutual labels:  unmaintained
elmo
DEPRECATED - Elmo ~ https://mozilla.github.io/elmo/
Stars: ✭ 32 (-95.07%)
Mutual labels:  unmaintained
Wifi
[unmaintained] WiFi tools for linux
Stars: ✭ 281 (-56.7%)
Mutual labels:  unmaintained
Swig
Take a swig of the best template engine for JavaScript.
Stars: ✭ 3,129 (+382.13%)
Mutual labels:  unmaintained
Garmr
INACTIVE - Security Testing Tool
Stars: ✭ 105 (-83.82%)
Mutual labels:  unmaintained
Bootstrap Tags
Bootstrap-themed jquery tag interface
Stars: ✭ 562 (-13.41%)
Mutual labels:  unmaintained
Mobx Store
A data store with declarative querying, observable state, and easy undo/redo.
Stars: ✭ 283 (-56.39%)
Mutual labels:  unmaintained
React Heatpack
A 'heatpack' command for quick React development with webpack hot reloading
Stars: ✭ 354 (-45.45%)
Mutual labels:  unmaintained
coma
a console mail user agent | obsolete: use mblaze
Stars: ✭ 13 (-98%)
Mutual labels:  unmaintained
Colors Of Image
A PHP Library for getting colors from images DEPRECATED
Stars: ✭ 273 (-57.94%)
Mutual labels:  unmaintained
Deprecated Mapbox Ios Sdk
REPLACED – use https://www.mapbox.com/ios-sdk instead
Stars: ✭ 325 (-49.92%)
Mutual labels:  unmaintained
rescuefox
DEPRECATED - demo game to drive 3D engine creation: rescue your pet space fox!
Stars: ✭ 35 (-94.61%)
Mutual labels:  unmaintained
Axe Cli
[Deprecated] A command-line interface for the aXe accessibility testing engine
Stars: ✭ 419 (-35.44%)
Mutual labels:  unmaintained
addon-sdk-content-scripts
DEPRECATED | Use WebExtensions instead | Add-ons demonstrating how to use content scripts in the Add-on SDK.
Stars: ✭ 23 (-96.46%)
Mutual labels:  unmaintained
Redditkit
An Objective-C wrapper for the reddit API
Stars: ✭ 299 (-53.93%)
Mutual labels:  unmaintained
Node Jscs
⤴️ JavaScript Code Style checker (unmaintained)
Stars: ✭ 5,026 (+674.42%)
Mutual labels:  unmaintained
Complexity Report
[UNMAINTAINED] Software complexity analysis for JavaScript projects
Stars: ✭ 465 (-28.35%)
Mutual labels:  unmaintained
Scaleapp
scaleApp is a JavaScript framework for scalable and maintainable One-Page-Applications
Stars: ✭ 353 (-45.61%)
Mutual labels:  unmaintained

newforms travis status

An isomorphic form-handling library for React.

(Formerly a direct port of the Django framework's django.forms library)

Other React Form Libraries

  • react-formal - uses a schema and leverages React's context feature to make it really simple to render fields and error messages

  • redux-form - manages form state for you, leaving you do the rendering exactly as you wish

Getting newforms

Node.js

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

npm install newforms
var forms = require('newforms')

By default, newforms will be in development mode. To use it in production mode, set the environment variable NODE_ENV to 'production' when bundling. To completely remove all development mode code, use a minifier that performs dead-code elimination, such as UglifyJS.

Browser bundle

The browser bundle exposes a global forms variable and expects to find global React variable to work with.

The uncompressed bundle is in development mode, so will log warnings about potential mistakes.

You can find it in the /dist directory.

Upgrade Guide

Documentation @ ReadTheDocs

Newforms Examples @ GitHub

Related Projects

Quick Guide

A quick introduction to defining and using newforms Form objects.

Design your Form

The starting point for defining your own forms is Form.extend().

Here's a simple (but incomplete!) definition of a type of Form you've probably seen dozens of times:

var SignupForm = forms.Form.extend({
  username: forms.CharField(),
  email: forms.EmailField(),
  password: forms.CharField({widget: forms.PasswordInput}),
  confirmPassword: forms.CharField({widget: forms.PasswordInput}),
  acceptTerms: forms.BooleanField({required: true})
})

A piece of user input data is represented by a Field, groups of related Fields are held in a Form and a form input which will be displayed to the user is represented by a Widget. Every Field has a default Widget, which can be overridden.

Rendering a Form

Forms provide helpers for rendering labels, user inputs and validation errors for their fields. To get you started quickly, newforms provides a React component which use these helpers to render a basic form structure.

At the very least, you must wrap rendered form contents in a <form>, provide form controls such as a submit button and hook up handling of form submission:

var Signup = React.createClass({
  render: function() {
    return <form onSubmit={this._onSubmit}>
      <forms.RenderForm form={SignupForm} ref="signupForm"/>
      <button>Sign Up</button>
    </form>
  },

  // ...

Rendering helpers attach event handlers to the inputs they render, so getting user input data is handled for you.

The RenderForm component handles creating a form instance for you, and setting up automatic validation of user input as it's given.

To access this form instance later, make sure the component has a ref name.

Handling form submission

The final step in using a Form is validating when the user attempts to submit.

First, use the ref name you defined earlier to get the form instance via the RenderForm component's getForm() method.

Then call the form's validate() method to ensure every field in the form is validated against its current user input.

If a Form is valid, it will have a cleanedData object containing validated data, coerced to the appropriate JavaScript data type when appropriate:

  propTypes: {
    onSignup: React.PropTypes.func.isRequired
  },

  _onSubmit: function(e) {
    e.preventDefault()

    var form = this.refs.signupForm.getForm()
    var isValid = form.validate()
    if (isValid) {
      this.props.onSignup(form.cleanedData)
    }
  }
})

Implementing custom validation

There's an obvious validation not being handled by our form: what if the passwords don't match?

This is a cross-field validation. To implement custom, cross-field validation add a clean() method to the Form definition:

clean: function() {
  if (this.cleanedData.password &&
      this.cleanedData.confirmPassword &&
      this.cleanedData.password != this.cleanedData.confirmPassword) {
    throw forms.ValidationError('Passwords do not match.')
  }
}

Live Quickstart Demo

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].