redux-form-auto

1.1.10 • Public • Published

Build Status

redux-form-auto

This library allows your React application to automatically generate forms and validation code using ReduxForm for state management. The form and validations are generated following a schema inspired by SimpleSchema.

At the moment the skins available are:

More skins will be added. Join me!

Project status

This is more or less abandonware. I will probably update for security concerns. Anyway, if you have a need, try to open an issue. If it's easy I may do it. And of course, PRs are welcome.

Play with a demo

Migration from 1.0.x

The library doesn't include bootstrap 3 styles by default any more. If you want to use bootstrap 3 skin you have to include its npm, see installation.

Installation

Choose the skin and import the corresponding package

$ npm install redux-form-auto-bootstrap3 --save

Current skins:

  • redux-form-auto-bootstrap3
  • redux-form-auto-bootstrap4
  • redux-form-auto-antd

Usage

1. Write schema

Write a schema for each model you have:

    import { Schema } from 'redux-form-auto-bootstrap3'
    // ... or ...
    import { Schema } from 'redux-form-auto-bootstrap4'
    // ... or ...
    import { Schema } from 'redux-form-auto-antd'

    export const client = new Schema('client', {
      name: {
        type: 'string',
        required: true,
        max: 32
      },
      age: {
        type: 'number'
      }
    })

Here we are saying that a client is required to have a name and providing its allowed length. Also client has age and it's a number.

Here you can find the complete list of types and validators available.

2. Render a form

<Autoform /> React component will generate connected inputs including translatable label, proper input types and error/warning messages:

    import { Autoform } from 'redux-from-auto-<skin>'
    import { client } from './models/client'

    const MyForm = ({ onSubmit }) =>
      <Autoform
        schema={client}
        onSubmit={onSubmit}
      />

Form will be validated following the rules set in the schema, beginning with the type itself.

It also allows you to build arrays from other schemas as ReduxForm's FieldArray. You just toss an array with another schema from elsewhere as first element and Autoform will allow you to add and remove elements:

    import { Schema } from 'redux-form-auto-<skin>'
    import { client } from './client'

    export const company = new Schema('company', {
      clients: {
        type: [client],
        minChildren: 10
      }
    })

Read the documentation to find out what else you can do:

You can also take the demo project as an example of use.

Rationale

One of the purposes of the library is to avoid repeating code by not having to write a set of input components for every entity. Also when time is of the essence, writing forms can be exasperating.

These are some of the advantages of using an automatic form system.

  • More DRY
  • More SSoT
  • ...so less bugs

Also redux-form-auto has some of its own

  • Validation is also automatic
  • Includes a translation system
  • It's easily expandable
  • It's simple
  • When possible tries to use convention over configuration

Help wanted

Let's have some fun automatizing the hell out of every UI library out there. Join me!

/redux-form-auto/

    Package Sidebar

    Install

    npm i redux-form-auto

    Weekly Downloads

    1

    Version

    1.1.10

    License

    MIT

    Unpacked Size

    124 kB

    Total Files

    45

    Last publish

    Collaborators

    • braben