redux-form-normalize-on-blur
Version:
a Field component that supports a normalizeOnBlur property
49 lines (33 loc) • 1.57 kB
Markdown
# redux-form-normalize-on-blur
[](https://travis-ci.org/jcoreio/redux-form-normalize-on-blur)
[](https://codecov.io/gh/jcoreio/redux-form-normalize-on-blur)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://badge.fury.io/js/redux-form-normalize-on-blur)
a `redux-form` `Field` component that supports a `normalizeOnBlur` property
# Usage
```sh
npm install --save redux-form-normalize-on-blur
```
```js
const { Field } = require('redux-form-normalize-on-blur')
```
or
```js
const { Field } = require('redux-form-normalize-on-blur/immutable')
```
## Example
The following field will trim its text when it loses focus:
```js
<Field
name="name"
normalizeOnBlur={(value) => value && value.trim()}
component={YourInputComponent}
/>
```
## API
### `Field`
Has the same API as `redux-form`'s `Field`, but it accepts an additional `normalizeOnBlur` property:
#### `normalizeOnBlur?: (value: any) => any`
Function that takes the current value and returns the normalized value.
NOTE: this happens before `parse` or `normalize`!