# reactstrap-input

> clone this project

Latest version **1.0.8** (published 2018-09-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install reactstrap-input
pnpm add reactstrap-input
yarn add reactstrap-input
bun add reactstrap-input
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2018-09-27 |
| First published | 2018-07-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ivandaho |

## Links

- npm: https://www.npmjs.com/package/reactstrap-input
- npm.io page: https://npm.io/package/reactstrap-input

## Dependencies (2)

- [approvejs](https://npm.io/package/approvejs.md) ^3.1.2
- [reactstrap](https://npm.io/package/reactstrap.md) ^6.3.0

## Recent versions

- 1.0.8 (latest) — 2018-09-27
- 1.0.7 — 2018-09-22
- 1.0.6 — 2018-09-21
- 1.0.5 — 2018-09-12
- 1.0.4 — 2018-09-12
- 1.0.3 — 2018-08-04
- 1.0.2 — 2018-08-03
- 1.0.1 — 2018-07-29
- 1.0.0 — 2018-07-27

## README

clone this project

```
npm install
```

### Commands:

starts development server with example page
```
npm run start
```

builds file into dist folder
```
npm run transpile
```

### to get local changes instantly:

link this package locally
```
npm link
```
start watching files and build latest changes by running
```
npm run watch
```

in the project folder where you want to see latest changes, install the project
```
npm install --save <project name>
```

to get local changes to this package to show up in your project instantly

```
npm link <project name>
```

Note: you will probably have to relink files after each install.

### Getting Started

How this works:

InputComponent/InputGroupComponent are controlled components that take in
"typical" controlled component props such as `value` and `handleChange`.
`handleChange` should be a function that uses `event.target.value` and
`event.target.id` dispatches an action to update state. (`valueKey` is
placed in `event.target.id`)

There should also be an empty object initialized in your store/state/reducer to
store validation results. this should be passed to InputComponent as
`validationObj`.

InputComponent will check `validationObj` for items validated via approvejs,
and update the reactstrap components accordingly.

As of now, validation is "manual". Hence, Inputs will not be validated upon
load unless implemented.

Typically, the `handleChange` function should update the InputComponent's
`value`, and also update (or initialize) `validationObj` each time it is
called.

If no corresponding key is found in `validationObj` , validation will be
skipped (assumed to be passed).

Validation will also be skipped if `saveButtonPressed` is false.


```
// example reducer default state
defaultState = {
    fields: {
        firstName: '',
        lastName: ''
        // ...other fields as needed
    },
    validation: {} // for storing validation results
}
```
And in your InputComponent:
```
// this.props = {...defaultState}
<InputComponent
    value={this.props.fields.value}
    validationObj={this.props.validation}
    ...
/>
```
Example onChange function, in `mapDispatchToProps`:
```
handleChange: (e) => {
    dispatch({
        type: CHANGE_FIELD_VALUE
        key: e.target.id,
        value: e.target.value,
    })
}
```
And in your reducer:
```
case 'CHANGE_FIELD_VALUE':
    // update field value
    newState.fields = Object.assign({}, state.fields);
    newState.fields[action.key] = action.value;

    // update validation result object with approvejs
    newState.validation = Object.assign({}, state.validation);
    newState.validation[action.key] = validationlib.validate(action.key, action.value);
    return newState;
```

In validationlib:
```
    validate: (key, value) => {
        if (!validationTypes[key]) {
            // no validation specified for key
            return false;
        }
        // see approvejs documentation for more info regarding rules
        let rules = validationTypes[key] ? validationTypes[key] : null;
        return approve.value(value, rules);
    }
```

### InputComponent Props


```
    handleChange // onChange function that should update a) the Input's value and b) validationObj
    saveButtonPressed // validation will only trigger if this is true
    validationObj // the validation object in state that stores validation results
    inputProps // props that will be passed to the reactstrap Input component
    value // value of the input
    valueKey // key used for controlled component and validation. passed in as input.id
    type // type of input, e.g 'text', 'textarea', 'number'
    rows // only applies if type === 'textarea'
    noFeedback // remove the FormFeedback portion
    colWidth // bootstrap col width for inline inputs
    label
    defaultValue
```

### TODO:
* use data-\* props instead of hogging `id` prop
* rethink about forcing validation at start/proper initialization of validationObj
* CI to publish changes made in this repository to npm

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