# react-form-utils

> Serialize/Deserialize form input, and lookup

Latest version **2.0.0** (published 2018-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-form-utils
pnpm add react-form-utils
yarn add react-form-utils
bun add react-form-utils
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-05-18 |
| First published | 2017-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | code@alvinsj.net |
| Maintainers | alvinsj |
| Keywords | reactjs, form, layout, builder, react-component |

## Links

- npm: https://www.npmjs.com/package/react-form-utils
- Repository: https://github.com/blacktangent/react-layout-builder
- Issues: https://github.com/blacktangent/react-layout-builder/issues
- npm.io page: https://npm.io/package/react-form-utils

## Dependencies (2)

- [object-assign](https://npm.io/package/object-assign.md) ^4.x.x
- [@alvinsj/form-serialize](https://npm.io/package/@alvinsj/form-serialize.md) ^0.7.2-alpha.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

- 2.0.0 (latest) — 2018-05-18
- 1.2.0 — 2018-05-18
- 2.0.0-beta.1 — 2017-11-07
- 2.0.0-alpha.9 — 2017-10-17
- 2.0.0-alpha.8 — 2017-10-17
- 2.0.0-alpha.7 — 2017-10-17
- 2.0.0-alpha.6 — 2017-10-12
- 2.0.0-alpha.5 — 2017-10-12
- 2.0.0-alpha.4 — 2017-10-12
- 2.0.0-alpha.3 — 2017-09-20
- 2.0.0-alpha.1 — 2017-09-20
- 1.1.7 — 2017-08-17
- 1.1.6 — 2017-08-17

## README

# react-form-utils

[![Build Status](https://travis-ci.org/blacktangent/react-layout-builder.svg?branch=master)](https://travis-ci.org/blacktangent/react-layout-builder)

`react-form-utils` provides helper functions to retrieve form props and form values

```
import {inputPropsLookup, inputValueLookup, formSerialize} from 'react-form-utils';
```

### `inputPropsLookup(fieldsProps, fieldName) `

Argument    | Type        | Example
:-----------| :-----------| :-----------
`fieldsProps`      | `object`      | `{name: {type: 'text'}, email: {type: 'email'}}`
`fieldName`   | `string`      | `name`, `email[0]`, `email[1]`

#### returns
`object`: props, e.g. `{type: 'text'}`

#### e.g.
```js
const fieldsProps = {
  name: { type: 'text' },
  age_group: {
    type: 'select',
    size: 4,
    options: []
  }
  address: {
    type: 'nested',
    fields: {
      street: {
        type: 'text'
      }
    }
  }  
};
const fieldName = 'address[0][street]';

const props = inputPropsLookup(fieldsProps, fieldName);
// <input name={fieldName} {...props} />
```

### `formSerialize(form)`

    formSerialize(form)  

Argument    | Type        | Example
:-----------| :-----------| :-----------
`form`      | `DOMNode`      | `form` element

#### returns
`object`. serialized, e.g. `{type: 'text'}`

#### e.g.
```js
// <form><input name="message" value="hello"/></form>

const values = formSerialize(this.form);
// { message: 'hello' }

```

### `inputValueLookup(values, fieldName) `

Argument    | Type        | Example
:-----------| :-----------| :-----------
`values`      | `object`      | `{address: [ {zip: '55555'} ]}`
`fieldName`   | `string`      | `address[0][zip]`

#### returns
`any`. input value, e.g. `{type: 'text'}`

#### e.g.
```js
const values = {
  name: 'Ali',
  age_group: '31-40'
  address: {
    0: {
      street: '13 Calle 49a'
     }
};
const fieldName = 'address[0][street]';

const value = inputValueLookup(values, fieldName);

// <input name={fieldName} value={value} />
```

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