Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arojunior/redux-form-field-wrapper

Redux-form fields wrapper
https://github.com/arojunior/redux-form-field-wrapper

javascript react redux redux-form

Last synced: about 2 months ago
JSON representation

Redux-form fields wrapper

Awesome Lists containing this project

README

        

# Redux-form Field Renderer

### Install
```shell
npm install redux-form-field-wrapper --save
```

### Usage
```javascript
import React from 'react'
import {Field, reduxForm} from 'redux-form'
import renderField from 'redux-form-field-wrapper'

const defaultConfig = {
divClass: 'form-group',
inputClass: 'col-md-10',
labelClass: 'col-md-2',
component: renderField
}

const Form = props => {
const {handleSubmit, pristine, invalid, reset, submitting} = props
return (




Send


)
}

export default reduxForm({
form: 'myForm'
})(Form)
```

### Output

```html



Name







E-mail




```

### What about validation?

Just add your own validation method and populate errors in case of fail

```javascript
const validate = values => {
const errors = {}
if ( ! checkUsername(values.email)) {
errors.email = 'Sorry, Dude. This username is already in use'
}
return errors
}

export default reduxForm({
form: 'myForm',
validate
})(Form)
```

### Need something easier?

```javascript
import renderField, {email} from 'redux-form-field-wrapper'

// ...Code

// ...Code

export default reduxForm({
form: 'myForm'
})(Form)
// Obs: Don't need validate property
```

***Validation methods available:***

* required
* maxLength
* number
* minValue
* email