├── .babelrc ├── .editorconfig ├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── examples ├── basic-state-access │ └── index.js ├── basic-usage │ └── index.js ├── cli.js ├── field-wrap-hoc │ └── index.js ├── field-wraps │ └── index.js ├── full-featured │ └── index.js ├── index.html ├── initial-values │ └── index.js ├── reset-form │ └── index.js ├── server.js ├── submit-handling │ └── index.js └── validation │ └── index.js ├── package-lock.json ├── package.json ├── src ├── Field.js ├── FieldTypes.js ├── Form.js ├── connectField.js └── index.js ├── test ├── .setup.js └── components │ └── connectField.js ├── todo.md └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-2", "react"] 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | npm-debug.log 5 | dist 6 | sandbox 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | examples 2 | src 3 | .babelrc 4 | .editorconfig 5 | .npmignore 6 | npm-debug.log 7 | todo.md 8 | webpack.* 9 | test 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Brad Westfall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ** NOT MAINTAINED ** 2 | 3 | When I wrote this library, redux-form was "king of the land" as far as React forms go. I wanted a similar API that provided meta state about forms and fields but without the redux part. This project did a great job of that. However, another project called [Formik](https://github.com/jaredpalmer/formik) emerged since I wrote `informative` and it does all the things I was trying to do and a few more. It's well maintained and I've recently updated my largest project to use it instead. 4 | 5 |
6 | 7 | # informative 8 | 9 | Informative is a `
` and `` Compound Component Stratagy that keep track of form and field state for you and can provide it to you in a several of ways. Create basic fields with a "redux-form" style `` API, or use render props to create a [re-usable "Field Wrap"](#field-wraps) with ``. 10 | 11 | ## Install 12 | 13 | ```sh 14 | npm install --save informative 15 | ``` 16 | 17 | 18 | ## Contents 19 | 20 | - [`` and ``](#form-and-field) 21 | - [``](#field-componentinput-) 22 | - [``](#field-componentselect-) 23 | - [``](#field-componenttextarea-) 24 | - [Built-in Fields](#built-in-fields) 25 | - [Custom Fields](#custom-fields) 26 | - [`onChange` for `` and ``](#onchange-for-field-and-form) 27 | - [Examples](#examples) 28 | - [Basic Usage](#basic-usage) 29 | - [Basic State Access](#basic-state-access) 30 | - [Submit Handling](#submit-handling) 31 | - [Redirects](#redirects) 32 | - [Validation](#validation) 33 | - [Top Level Access to `formState`](#top-level-access-to-formstate) 34 | - [Initial Values](#initial-values) 35 | - [Reset Form](#reset-form) 36 | - [Field Wraps](#field-wraps) 37 | - [Field Abstraction](#field-abstraction) 38 | - [`connectField` HoC](#connectfield-hoc) 39 | - [`formState`](#formstate) 40 | - [`fieldState`](#fieldstate) 41 | 42 | 43 | # `` and `` 44 | 45 | `` and `` are the basic building blocks of the API. Always use the `` component to start an informative form as it is the main entry-point into the API. 46 | 47 | The `` component is used to register each field in your form with the API. It also bootstraps state into the `Form` component. It always requires a `name` prop which must be unique for this specific form unless using radio buttons (in which the names should be the same). To designate what type of field will be created, pass a `component` prop. The `component` prop can be a string or a custom component. In this example we're showing how to use strings to make basic fields. 48 | 49 | ```jsx 50 | import React from 'react' 51 | import { Form, Field } from 'informative' 52 | 53 | const MyForm = props => ( 54 | 55 | 56 | 57 | 58 | ) 59 | ``` 60 | 61 | 62 | ### `` 63 | 64 | In the previous example `` is used to make a DOM element similar to ``. The difference though is that since we're using ``, the input is wired into the form's state and responds to DOM events like `onChange` and a few others. 65 | 66 | When using `` this way with `component="input"`, a `type` property can also be used to designate other input types similar to ordinary HTML. If no `type` is specified, the default is `text`. 67 | 68 | Under the hood, `` uses `` when passing `component="input"` into `` (as long as the type isn't a radio or checkbox). See more on `` below in [Built-in Fields](#built-in-fields). 69 | 70 | 71 | #### Checkbox Inputs 72 | 73 | For checkboxes, be sure to specify a prop for `checked` always, even if the value is false, supply `checked={false}`. Also, checkboxes should always have a `value` prop. When the checkbox is checked, the value in the `value` prop is what is applied to the field in terms of the field's state value. If the checkbox is unchecked, the field's state value will be an empty string. 74 | 75 | ```jsx 76 | 77 | ``` 78 | 79 | Under the hood, `` uses `` when passing `component="input" type="checkbox"` into ``. See more on `` below in [Built-in Fields](#built-in-fields). 80 | 81 | 82 | #### Radio Inputs 83 | 84 | For radios, you do not need to always specify `checked` as you do with checkboxes. However, you always need to specify a `value` prop for each radio in the group. A radio group is two or more radio inputs that share the same `name`. In fact, this is the only type of `` that can share a `name` with another ``. The value reported by the field's state will be the value of the respective radio that is checked. If no radio is checked, the value in the field's state will be an empty string. 85 | 86 | ```jsx 87 | 88 | 89 | ``` 90 | 91 | Under the hood, `` uses `` when passing `component="input" type="radio"` into ``. See more on `` below in [Built-in Fields](#built-in-fields). 92 | 93 | 94 | ### `` 95 | 96 | A `