2.6.0 • Published 2 years ago

react-good-form v2.6.0

Weekly downloads
90
License
MIT
Repository
github
Last release
2 years ago

Stable Release license TypeScript

React Good Form

Good Form implementation for React. Easy drop-in validation. Supports arrays and nested structures. Helps to reduce boilerplate without being opinionated on style. Typescript support.

Installation

npm install react-good-form

Simple Example

Good Form supports basic validations such as email, minLength, maxLength etc. out of the box. It automatically emits onChange events and provides values for fields. onSubmit callback is only triggered when submitting a valid form. Otherwise form will focus to first invalid field.

import { Form } from "react-good-form"

class EmailForm extends React.Component {
  state = {
    email: ""
  }
  render() {
    return (
      <Form
        value={this.state}
        onChange={person => {
          this.setState(person)
        }}
        onSubmit={() => {
          alert(this.state.email)
        }}
      >
        {({ Input }, { invalid, touched }) => (
          <div>
            <h1>Log in</h1>
            <div style={{ color: invalid("email") && touched("email") ? "red" : undefined }}>
              <label>Email</label>
              <Input email required for="email" />
            </div>
            <button>OK</button>
          </div>
        )}
      </Form>
    )
  }
}

Extendable

You can create arbitary rules by providing a rule function.

const rule = email => email.endsWith("hotmail.com")

<Input
  rule={rule}
  email={true}
  for="email"
/>

Or an regular expression.

const regExp = /(123456|password)/

<Input
  type="password"
  regExp={regExp}
  for="password"
/>

Supports nested structures

Provide paths to nested structures as arrays.

<div style={{ color: invalid(["address", "street"]) && touched(["address", "street"]) && "red" }}>
  <label>Street</label>
  <Input for={["address", "street"]} minLength={5} maxLength={100} />
</div>

Documentation

https://osaario.github.io/react-good-form/

2.6.0

2 years ago

2.5.0

2 years ago

2.3.2

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago