# mobx-forms

> A simple form management for Mobx & React.

Latest version **0.2.1** (published 2016-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install mobx-forms
pnpm add mobx-forms
yarn add mobx-forms
bun add mobx-forms
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2016-10-14 |
| First published | 2016-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | oreqizer |
| Maintainers | oreqizer |
| Keywords | form, forms, mobx, react |

## Links

- npm: https://www.npmjs.com/package/mobx-forms
- Repository: https://github.com/oreqizer/mobx-forms
- Homepage: https://github.com/oreqizer/mobx-forms#readme
- Issues: https://github.com/oreqizer/mobx-forms/issues
- npm.io page: https://npm.io/package/mobx-forms

## Dependencies (2)

- [ramda](https://npm.io/package/ramda.md) ^0.22.1
- [invariant](https://npm.io/package/invariant.md) ^2.2.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2016-10-14
- 0.2.0 — 2016-10-14
- 0.1.3 — 2016-10-07
- 0.1.2 — 2016-10-07
- 0.1.1 — 2016-10-07
- 0.1.0 — 2016-10-04
- 0.0.5 — 2016-08-25
- 0.0.4 — 2016-08-25
- 0.0.3 — 2016-08-24
- 0.0.2 — 2016-08-24
- 0.0.0 — 2016-08-21

## README

# mobx-forms

A simple form manager for [React](https://facebook.github.io/react/) and [Mobx](https://github.com/mobxjs/mobx).

> Heavily inspired by and based on [Redux Form](https://github.com/erikras/redux-form)! Be sure to check it out if you're a Redux fan.

## TODO

- [ ] namespace types
- [ ] add docs

## ROADMAP

1. finish the api (mainly submitting/async validation)
4. better README :blush:

### Installation

`npm i --save mobx-forms`

### Usage

Use `Provider` from `mobx-react` and supply the form store to it as `mobxForms`.

```javascript
import { FormsStore } from 'mobx-forms';
import { Provider } from 'mobx-react';

import YourApp from './YourApp';

const Root = () =>
  <Provider mobxForms={new FormsStore()}>
    <YourApp>
  </Provider>;

export default Root;
```

Initializing a form:

```javascript
import React from 'react';
import { observer } from 'mobx-react';

import { mobxForm, Field, FieldArray } from 'mobx-forms';

const Form = props => (
  <div>
    My field:
    <Field
      name="myField"
      component={Input}
    />
    My flat array:
    <FieldArray
      name="flatarray"
      component={FlatArray}
      flat
    />
    My multi-field array:
    <FieldArray
      name="deeparray"
      component={DeepArray}
    />
  </div>
);

export default mobxForm({
  form: 'myForm',
})(Form);
```
 
Example of a `FlatArray` and `DeepArray`:

```javascript
const FlatArray = observer(props =>
  <div>
    {props.fields.map((index) =>
      <Field
        name="flatfield"
        key={index}
        index={index}
        component="input"
      />
    )}
    <button onClick={props.fields.push}>
      Add field
    </button>
    <button onClick={props.fields.pop}>
      Remove field
    </button>
  </div>
);

const DeepArray = observer(props =>
  <div>
    {props.fields.map(index =>
      <div key={index}>
        name:
        <Field
          name="name"
          index={index}
          component={Input}
        />
        surname:
        <Field
          name="surname"
          index={index}
          component="input"
        />
      </div>
    )}
    <button onClick={props.fields.push}>
      Add fields
    </button>
    <button onClick={props.fields.pop}>
      Remove fields
    </button>
  </div>
);
```

That's it! You will get the form's instance as a prop named `form`.

`Field` accepts either a *string* or a *component*. It will receive the necessary properties. More detailed docs incoming.

---
_Source: https://npm.io/package/mobx-forms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
