# react-uforms

> Simple and elegant forms for your React application

Latest version **3.7.1** (published 2023-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-uforms
pnpm add react-uforms
yarn add react-uforms
bun add react-uforms
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.7.1 |
| Published | 2023-05-24 |
| First published | 2018-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 287.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 8 |
| Author | Bohdan Protsiuk |
| Maintainers | summerua, smnkgv, garretua, usualdesigner, skyfortress |
| Keywords | react, form, uform, react-uform, react form, react forms, typescirpt |

## Links

- npm: https://www.npmjs.com/package/react-uforms
- Repository: https://github.com/bilberrry/react-uforms
- Homepage: https://github.com/bilberrry/react-uforms#readme
- Issues: https://github.com/bilberrry/react-uforms/issues
- npm.io page: https://npm.io/package/react-uforms

## Dependencies (9)

- [zustand](https://npm.io/package/zustand.md) ^4.3.7
- [classnames](https://npm.io/package/classnames.md) ^2.3.2
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^4.4.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.xorwith](https://npm.io/package/lodash.xorwith.md) ^4.5.0
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0
- [lodash.transform](https://npm.io/package/lodash.transform.md) ^4.6.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

- 3.7.1 (latest) — 2023-05-24
- 3.0.0-beta.1 (beta) — 2021-12-22
- 3.0.0-alpha.6 (alpha) — 2021-12-18
- 3.7.0 — 2023-04-03
- 3.6.0 — 2022-12-27
- 3.5.0 — 2022-11-01
- 3.4.2 — 2022-08-31
- 3.4.1 — 2022-08-31
- 3.4.0 — 2022-08-08
- 2.8.1 — 2022-08-07
- 2.8.0 — 2022-08-07
- 3.3.0 — 2022-06-03
- 3.2.7 — 2022-05-27
- 3.2.6 — 2022-05-25
- 3.2.5 — 2022-02-15
- … 73 more at https://npm.io/package/react-uforms/versions

## README

# react-uforms
[![npm version](https://badge.fury.io/js/react-uforms.svg)](https://badge.fury.io/js/react-uforms)
![build status](https://github.com/bilberrry/react-uforms/actions/workflows/workflow.yml/badge.svg?branch=master)
![TypeScript](https://img.shields.io/npm/types/typescript)
![NPM](https://img.shields.io/npm/l/react-uforms.svg)

Simple and elegant forms for your React application.

### Installation
Using Yarn
```bash
yarn add react-uforms
```

Or NPM

```bash
npm install react-uforms --save
```
## Usage

### 1. Simple example
```jsx
import { Form, Text } from 'react-uforms';

const example = (
  <Form onSubmit={(formApi, values) => console.log(values)}>
    <label htmlFor="email">Email</label>
    <Text type="text" id="email" name="email" />
    
    <label htmlFor="password">Password</label>
    <Text type="password" id="password" name="password" />
    
    <button type="submit">Submit</button>
  </Form>
);
```

### 2. Validation
```jsx
import { Form, Text } from 'react-uforms';
import * as yup from 'yup';
    
const example = (
  <Form
    validation={yup.object({
      email: yup.string().required('Email is required').email(),
      password: yup
        .string()
        .required('Password is required')
        .matches(/^(?=.*[a-z]).+$/, 'At least 1 lowercase alphabetical character')
        .matches(/^(?=.*[A-Z]).+$/, 'At least 1 uppercase alphabetical character')
        .matches(/^(?=.*\d+).+$/, 'At least 1 numeric character'),
    })}
    onSubmit={(formApi, values) => console.log(values)}
    onError={(formApi, errors) => console.log(errors)}
  >
    <label htmlFor="email">Email</label>
    <Text type="text" id="email" name="email" />
  
    <label htmlFor="password">Password</label>
    <Text type="password" id="password" name="password" />
  
    <button type="submit">Submit</button>
  </Form>
);
```

### 3. Pre-filled form
```jsx
import { Form, Text, TextArea } from 'react-uforms';
import * as yup from 'yup';
    
const example = (
  <Form
    defaultValues={{
      id: 1,
      email: 'foo.bar@example.com',
      profile: {
        firstName: 'Foo',
        lastName: 'Bar',
        bio: 'Travel blogger',
      },
      createdAt: '2018-04-25T23:36:02+00:00'
    }}
    validation={yup.object({
      email: yup.string().required('Email is required').email(),
      profile: yup.object({
        firstName: yup.string().required(),
        lastName: yup.string().required(),
        bio: yup.string(),
      }),
    })}
    onSubmit={(formApi, values) => console.log(values)}
    onError={(formApi, errors) => console.log(errors)}
  >
    <label htmlFor="email">Email</label>
    <Text type="text" id="email" name="email" />

    <label htmlFor="firstName">First Name</label>
    <Text type="text" id="firstName" name="profile.firstName" />

    <label htmlFor="lastName">Last Name</label>
    <Text type="text" id="lastName" name="profile.lastName" />

    <label htmlFor="bio">Bio</label>
    <TextArea id="bio" name="profile.bio" />

    <button type="submit">Submit</button>
  </Form>
);
```

### 4. Errors customization
```jsx
import { Form, Text, FieldError } from 'react-uforms';
import * as yup from 'yup';
    
const example = (
  <Form
    validation={yup.object({
      email: yup.string().required('Email is required').email(),
      profile: yup.object({
        firstName: yup.string().required(),
        lastName: yup.string().required(),
        bio: yup.string(),
      }),
    })}
    classes={{
      field: {
        error: "your-error-class",
        invalid: "your-invalid-input-class",
      },
    }}
    onSubmit={(formApi, values) => console.log(values)}
    onError={(formApi, errors) => console.log(errors)}
  >
    <label htmlFor="email">Email</label>
    <Text type="text" id="email" name="email" hideError={true} />
    <strong><FieldError name="email" /></strong>

    <label htmlFor="firstName">First Name</label>
    <Text type="text" id="firstName" name="profile.firstName" hideError={true} />
    <FieldError name="profile.firstName" className="add-some-error-class" />

    <label htmlFor="lastName">Last Name</label>
    <Text type="text" id="lastName" name="profile.lastName" />

    <button type="submit">Submit</button>
  </Form>
);
```

### 5. Other fields
```jsx
import { Form, Text, Select, TextArea, RadioGroup, RadioGroupItem, Checkbox } from 'react-uforms';
    
const example = (
  <Form
    onSubmit={(formApi, values) => console.log(values)}
    onError={(formApi, errors) => console.log(errors)}
  >
    <label htmlFor="email">Email</label>
    <Text id="email" name="email" disabled={true} />

    <label htmlFor="password">Password</label>
    <Text type="password" id="password" name="password" />

    <label htmlFor="country">Country</label>
    <Select
      id="country"
      name="country"
      options={[
        { value: null, name: 'Select country' },
        { value: 'US', name: 'United States' },
        { value: 'CA', name: 'Canada' },
        { value: 'UK', name: 'United Kingdom', disabled: true }
      ]}
    />

      <div className="radio-group">
        <RadioGroup name="gender">
          <div className="radio">
            <RadioGroupItem value="male" id="e7_gender_male" />
            <label htmlFor="e7_gender_male">Male</label>
          </div>
          <div className="radio">
            <RadioGroupItem value="female" id="e7_gender_female" />
            <label htmlFor="e7_gender_female">Female</label>
          </div>
        </RadioGroup>
      </div>

    <label htmlFor="bio">Bio</label>
    <TextArea id="bio" name="bio" emptyValue={null} />

    <div className="checkbox-group">
      <div className="checkbox">
        <Checkbox name="newsletter" onValue={1} offValue={0} id="newsletter" />
        <label htmlFor="newsletter">Receive Weekly Updates</label>
      </div>
    </div>
    
    <button type="submit">Submit</button>
  </Form>
);
```

### 6. Custom field
```jsx
import { Form, Field } from 'react-uforms';

const example = (
  <Form
    onSubmit={(formApi, values) => console.log(values)}
    defaultValues={{
      email: 'test@example.com',
      profile: {
        isPublic: true,
        firstName: 'John',
        lastName: 'Brown',
      },
    }}
  >
    <Field name="profile.isPublic">
      {({ setValue, getValue }) => (
        <button type="button" onClick={() => setValue(!getValue())}>
          {getValue() ? 'on' : 'off'}
        </button>
      )}
    </Field>
    <button type="submit">Submit</button>
  </Form>
);
```

## Authors

* **Bohdan Protsiuk** - [summerua](https://github.com/summerua)

## License

MIT License - see the [LICENSE](LICENSE) file for details

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