0.7.1 • Published 6 years ago

react-connect-form v0.7.1

Weekly downloads
35
License
MIT
Repository
github
Last release
6 years ago

react-connect-form

Controlled forms for React.

Quick Links

Examples

Basic

import { Form, Field, Submit } from "react-connect-form"

const UserForm = () => (
  <Form onSubmit={console.log}>
    <Field
      name="first_name"
      type="text"
      placeholder="First name"
    />
    <Field
      name="last_name"
      type="text"
      placeholder="Last name"
    />
    <Field
      name="email"
      type="text"
      placeholder="Email"
    />
    <Submit>Submit</Submit>
  </Form>
)

Validation

import { Form, Field, Submit } from "react-connect-form"
import regex from 'regex-email'

function isEmail(value) {
  if (!regex.test(value)) {
    return "Please enter a valid email address"
  }
}

const EmailForm = () => (
  <Form onSubmit={console.log}>
    <Field
      name="email"
      type="text"
      placeholder="Email"
      validators={[isEmail]}
    />
    <Submit>Submit</Submit>
  </Form>
)

Async Validation

import { Form, Field, Submit, validators } from "react-connect-form"
const { isEmail } = validators

function isUniqueEmail(value) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (value === "robert@gmail.com") {
        reject("Email is already in use")
      } else {
        resolve()
      }
    }, 1000)
  })
}

const EmailForm = ({ handleSubmit }) => (
  <Form onSubmit={handleSubmit}>
    <Field
      name="email"
      type="text"
      placeholder="Email"
      validators={[isEmail, isUniqueEmail]}
    />
    <Submit>Submit</Submit>
  </Form>
)

Conditional Fields

Stepped Forms

Nested Forms

API

Components

<Form />

<Field />

<Submit />

Connectors

createForm

createField

withForm

Helpers

validators

0.7.1

6 years ago

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago