Skip to content
Snippets Groups Projects
Commit c014db5d authored by Alf Eaton's avatar Alf Eaton
Browse files

Refactor ValidatedField

parent 1bb6fd11
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"react-router": "^3.0.5", "react-router": "^3.0.5",
"react-tag-autocomplete": "^5.4.1", "react-tag-autocomplete": "^5.4.1",
"redux": "^3.6.0", "redux": "^3.6.0",
"redux-form": "^7.0.4",
"xpub-fonts": "^0.0.2" "xpub-fonts": "^0.0.2"
}, },
"devDependencies": { "devDependencies": {
......
import React from 'react' import React from 'react'
import classnames from 'classnames' import classnames from 'classnames'
import classes from './ValidatedField.local.scss' import classes from './ValidatedField.local.scss'
import { Field } from 'redux-form'
// TODO: pass ...props.input to children automatically? // TODO: pass ...props.input to children automatically?
const ValidatedField = ({ form, children, error, warning }) => ( const ValidatedField = ({ component, ...rest }) => (
<div> <Field
{children} {...rest}
component={({ meta, input }) => (
<div>
{component(input)}
<div className={classes.messages}> <div className={classes.messages}>
{error && ( {meta.error && (
<div className={classnames(classes.message, classes.error)}> <div className={classnames(classes.message, classes.error)}>
{error} {meta.error}
</div> </div>
)} )}
{warning && ( {meta.warning && (
<div className={classnames(classes.message, classes.warning)}> <div className={classnames(classes.message, classes.warning)}>
{warning} {meta.warning}
</div>
)}
</div> </div>
)} </div>
</div> )}
</div> />
) )
export default ValidatedField export default ValidatedField
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment