# ic-formable

> A react form library

Latest version **0.0.3** (published 2017-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install ic-formable
pnpm add ic-formable
yarn add ic-formable
bun add ic-formable
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-10-17 |
| First published | 2017-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Nick Wargnier |
| Maintainers | nbwar |
| Keywords | react, forms |

## Links

- npm: https://www.npmjs.com/package/ic-formable
- Repository: https://github.com/nbwar/icformable
- Homepage: https://github.com/nbwar/icformable#readme
- Issues: https://github.com/nbwar/icformable/issues
- npm.io page: https://npm.io/package/ic-formable

## Dependencies (3)

- [radium](https://npm.io/package/radium.md) ^0.19.5
- [validator](https://npm.io/package/validator.md) ^9.0.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.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

- 0.0.3 (latest) — 2017-10-17
- 0.0.2 — 2017-10-17

## README

# ICFormable - React Forms

ICFormable provides a consistent way to create forms, inputs, and validations using React.

#### Features

* Function and flexible validation using Validator.js (https://github.com/chriso/validator.js) or custom regex
* Flexibility to build custom inputs
* onSubmit callback with form model serialized. No more “e.target.value” for every input!
* Pass “serverErrors” to the form that will map to each component appropriately

## How to use

**install**

```
npm install ic-formable
```

#### Components

**Form**

The base component to wrap all inputs types in to inherit ICFormable functionality.

**Props:**

* **onSubmit** - Submit callback that will provide model object w/ form values with key being “name” attribute
* **serverErrors** - marks errors on each input based on the input's “name” attribute
* **formProps** - Props to pass to html <form> element

```js
import { Form }     from 'icformable'
import ICTextField from 'store_app/components/shared/ICFormable/ICTextField'

class SomeComponent extends React.Component {
  state = {
    serverErrors: null
  }

  handleFormSubmit = (model) => {
    console.log(model)
  }

  render() {
    const formProps = {} // HTML form props

    return (
      <Form
        onSubmit={this.handleFormSubmit}
        serverErrors={this.state.serverErrors}
        formProps={formProps}
      >
        <ICTextField
          floatingLabelText="Email"
          name="email"
          hintText="jonnyappleseed@example.com"
          validations={{isEmail: null, isLength: {min: 3, max: 15}}}
          validationErrorText="Sorry, please enter a valid email."
          required
        />
        <button type="submit"> Submit </button>
      </Form>
    )
  }
}

export default SomeComponent
```


## Build Custom Components

#### FormComponent

In order to build custom inputs you'll want to use FormComponent as a Higher Order Component to inherit validation and form functionality.

**Props:**

* **name** (required) - the key for the form model
* **disabled** - to disable the input
* **required** - to mark the field as a required field
* **regexValidation** - a regex string to validate via regex
* **validations** - Validator.js (https://github.com/chriso/validator.js) validations use syntax: {validatorMethod: arguments}

```js
import { FormComponent } from 'icformable'

@FormComponent
class ICCustomInput extends React.Component {
  static propTypes = {
    name    : React.PropTypes.string.isRequired,
    disabled: React.PropTypes.bool,
    required: React.PropTypes.bool,
  }

  render() {
    return (
      <div>
        <input
          name={this.props.name}
          disabled={this.props.disabled}
          required={this.props.required}
        />
      </div>
    )
  }
}

export default ICCustomInput
```

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