# react-form-validation-hoc

> Form validation for React

Latest version **1.1.9** (published 2020-02-11) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-form-validation-hoc
pnpm add react-form-validation-hoc
yarn add react-form-validation-hoc
bun add react-form-validation-hoc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.9 |
| Published | 2020-02-11 |
| First published | 2018-10-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | tingxinCY |
| Maintainers | tingxin_cy |
| Keywords | react, form, validation |

## Links

- npm: https://www.npmjs.com/package/react-form-validation-hoc
- Repository: https://github.com/tingxinCY/react-form-validation
- Homepage: https://github.com/tingxinCY/react-form-validation#readme
- Issues: https://github.com/tingxinCY/react-form-validation/issues
- npm.io page: https://npm.io/package/react-form-validation-hoc

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^16.6.0
- [immutable](https://npm.io/package/immutable.md) ^3.8.2
- [async-validator](https://npm.io/package/async-validator.md) ^1.10.0

## 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

- 1.1.9 (latest) — 2020-02-11
- 1.1.8 — 2020-02-11
- 1.1.7 — 2019-11-13
- 1.1.6 — 2018-12-17
- 1.1.5 — 2018-11-14
- 1.1.4 — 2018-11-14
- 1.1.3 — 2018-11-14
- 1.1.2 — 2018-11-14
- 1.1.1 — 2018-11-14
- 1.1.0 — 2018-11-14
- 1.0.0 — 2018-10-28

## README

# react-form-validation
Form validation for React

## Install

```bash
$ tnpm install react-form-validation-hoc --save
```

## Usage
Please refer to [async-validator](https://github.com/yiminghe/async-validator) for verification rules

## Example
```javascript
import React from 'react';
import create from 'react-form-validation-hoc';

class MyForm extends React.Component {
  state = {
    name: '',
    sex: '',
    school: '',
  }

  handleSubmit = (event) => {
    event.preventDefault();
    this.props.validator.validateFields((errors, values) => {
      console.log(errors); // eg. { name: "please enter your name", data.sex: "Please fill in male or female", data.school: "school is required" }
      console.log(values); // eg. { name: "tony", data: { sex: "male", school: "ABC School" } }
    });
  }

  render() {
    const { FieldDecorator, errors } = this.props.validator;
    return (
      <form onSubmit={this.handleSubmit}>
        <div>
          <FieldDecorator
            name={'name'}
            value={this.state.name}
            rules={[
              { required: true, message: 'please enter your name' },
            ]}
          />
          name:
          <input
            value={this.state.name}
            onChange={(event) => {
              this.setState({
                name: event.target.value,
              });
            }}
          />
        </div>
        <div>name error: <span style={{ color: 'red' }}>{errors.name}</span></div>

        <div>
          <FieldDecorator
            name={'data.sex'}
            value={this.state.sex}
            rules={[
              {
                validator(rule, value, callback) {
                  if (value === 'male' || value === 'female') {
                    callback();
                  } else {
                    callback('Please fill in male or female');
                  }
                },
              },
            ]}
          />
          sex:
          <input
            value={this.state.sex}
            onChange={(event) => {
              this.setState({
                sex: event.target.value,
              });
            }}
          />
        </div>
        <div>sex error: <span style={{ color: 'red' }}>{errors['data.sex']}</span></div>

        <div>
          <FieldDecorator
            name={'data.school'}
            value={this.state.school}
            rules={[
              { required: true, message: 'school is required' },
            ]}
          />
          School:
          <input
            value={this.state.school}
            onChange={(event) => {
              this.setState({
                school: event.target.value,
              });
            }}
          />
        </div>
        <div>school error: <span style={{ color: 'red' }}>{errors['data.school']}</span></div>

        <input type="submit" value="Submit" />
      </form>
    );
  }
}

export default create()(MyForm);
```

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