# @blendmedia/formality

> A simple and composable react form library

Latest version **1.0.0-alpha.39** (published 2017-11-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blendmedia/formality
pnpm add @blendmedia/formality
yarn add @blendmedia/formality
bun add @blendmedia/formality
```

## 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 | 1.0.0-alpha.39 |
| Published | 2017-11-09 |
| First published | 2017-05-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ashley Blurton |
| Maintainers | ashleyblurton |

## Links

- npm: https://www.npmjs.com/package/@blendmedia/formality
- Repository: https://github.com/blendmedia/formality
- Homepage: https://github.com/blendmedia/formality#readme
- Issues: https://github.com/blendmedia/formality/issues
- npm.io page: https://npm.io/package/@blendmedia/formality

## Dependencies (5)

- [debounce](https://npm.io/package/debounce.md) ^1.0.0
- [validator](https://npm.io/package/validator.md) ^5.4.0
- [classnames](https://npm.io/package/classnames.md) ^2.2.5
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [core-decorators](https://npm.io/package/core-decorators.md) ^0.12.3

## Recent versions

- 1.0.0-alpha.39 (latest) — 2017-11-09
- 1.0.0-alpha.38 — 2017-05-23
- 1.0.0-alpha.37 — 2017-05-23

## README

#Formality

React forms with courtesy.

## Introduction

Formality aims to be a simple and composable library for validated input and forms in React. The provided input components can be used without any parent container, and can be interacted with like a standard component via `onChange`.

Alternatively your inputs can be wrapped in a `<Form />` component which will retrieve all data and pass it to the `onSubmit` event handler- which is only fired when all input is valid (unless you pass `submitOnInvalid`)!. 

### Simple validation

Validation is done by passing validation functions as children to an Input component. This method is inspired by the [validation library by vacuumlabs](https://github.com/vacuumlabs/validation) ([Video](https://www.youtube.com/watch?v=FqscLiODo5c)).

## Usage

### Standard validation with debounce

```javascript
import { Input, isEmail } from "@thinmartian/formality";

<Input debounce={300} name="email">
    <IsEmail />
</Input>
```
    
### Validation with message override

```javascript
import { Input, Required } from "@thinmartian/formality";

<Input name="username">
    <Required message="Please supply a username" />
</Input>
```

### Async validation

```javascript
const AsyncCheck = ({ value }) => {
    return new Promise(resolve => {
        setTimeout(() => resolve(value === "correct"), 1000);
    });
}
// Uncomment to mark validation as asynchronous
// it will be treated as async without executing the promise
// AsyncCheck.async = true;

import { Input, Required } from "@thinmartian/formality";

<Input name="server_check">
    <Required />
    <AsyncCheck />
</Input>
```

### Creating a validator (manual)

```javascript
const MyCustomValidator = ({ value, is /* props */}) => {
    // Can return a boolean, message will be loaded from props or parent Input
    // return value === is; 
    return {
        vaiid: value === is,
        message: `Value does not equal ${is}`,
        key: "equal"
    }
}

// Usage
<MyCustomValidator is="matched" />
```

### Creating a validator (from a boolean function via compose)

```javascript
import { compose } from "@thinmartian/formality"
import isAlpha from "validator/lib/isAlpha"

const IsAlpha = compose(
    isAlpha,
    "Please enter an alphabetical string only",
    "alpha"
)

// Usage
<IsAlpha />
```

## Examples

Please see the `examples/` directory for example usage of components


## More Documentation Coming Soon!

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