Skip to content

Wroud/react-painlessform

Repository files navigation

react-painlessform

Uses React 16.3 Context

Painless Form is a bunch of React Components that helps you:

  • Validate form via custom validator or Yup.Schema or combined validator!
  • Calculate fields
  • Use typescript for type checking in fields!
  • Create reusable form parts with own Validation & Transform

without any configs only declarative style.

Travis codecov GitHub issues GitHub license npm version npm downloads

Install

npm install --save react-painlessform

Documentation

Examples

import { createFormFactory } from "react-painlessform";

interface IModel {
    field: number;
    field2: string;
}

const { Form, Field } = createFormFactory<IModel>();

const MyForm = (props) => {
    return (
        <Form initValues={values} onModelChange={onModelChange}>
            <div>
                <Field name={f=>f.field}>
                    {({ inputHook, rest }) => <input {...inputHook, ...rest} />}
                </Field>
                <Field name={f=>f.field2}>
                    {({ inputHook, rest }) => <input {...inputHook, ...rest} />}
                </field>
                <button type="submit">Submit</button>
            </div>
        </Form>
    );
}