# define-form

> Define form offers alternative typescript bindings for [final-form](https://github.com/final-form/final-form). The key difference is that the form data is now a strongly typed object, rather than an any. This makes the `initialValues` config option requir

Latest version **2.0.1** (published 2018-07-30) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install define-form
pnpm add define-form
yarn add define-form
bun add define-form
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-07-30 |
| First published | 2018-01-17 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Maintainers | forbeslindesay |

## Links

- npm: https://www.npmjs.com/package/define-form
- Repository: https://github.com/ForbesLindesay/define-form/tree/master/packages/define-form
- Issues: https://github.com/ForbesLindesay/define-form/issues
- npm.io page: https://npm.io/package/define-form

## Dependencies (2)

- [final-form](https://npm.io/package/final-form.md) ^4.2.0
- [@types/node](https://npm.io/package/@types/node.md) ^8.0.33

## Recent versions

- 2.0.1 (latest) — 2018-07-30
- 2.0.0 — 2018-07-30
- 1.2.1 — 2018-02-20
- 1.2.0 — 2018-02-20
- 1.1.0 — 2018-02-07
- 1.0.0 — 2018-01-17
- 0.0.2 — 2018-01-17
- 0.0.1 — 2018-01-17

## README

# Define Form

Define form offers alternative typescript bindings for [final-form](https://github.com/final-form/final-form). The key difference is that the form data is now a strongly typed object, rather than an any. This makes the `initialValues` config option required.

## Installation

```
yarn add define-form
```

## Usage

```typescript
import defineForm from 'define-form';

interface FormState {
  name: string;
}
type ErrorValue = string;
const form = defineForm<FormState, ErrorValue>({
  initialValues: {name: ''}, // required
  onSubmit, // required
  validate
})

// Subscribe to form state updates
const unsubscribe = form.subscribe(
  formState => {
    // Update UI
  },
  { // FormSubscription: the list of values you want to be updated about
    dirty: true,
    valid: true,
    values: true
  }
})

// Subscribe to field state updates
const unregisterField = form.registerField(
  'username',
  fieldState => {
    // Update field UI
    const { blur, change, focus, ...rest } = fieldState
    // In addition to the values you subscribe to, field state also
    // includes functions that your inputs need to update their state.
  },
  { // FieldSubscription: the list of values you want to be updated about
    active: true,
    dirty: true,
    touched: true,
    valid: true,
    value: true
  }
)

// Submit
form.submit() // only submits if all validation passes
```

If you like this, you may also want to check out [react-define-form](https://www.npmjs.com/package/react-define-form)

## License

MIT

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