Skip to content

Instantly share code, notes, and snippets.

@timcase
Created April 30, 2017 10:03
Show Gist options
  • Save timcase/dd0156288cb6f8c4c3c7f259fcada5e1 to your computer and use it in GitHub Desktop.
Save timcase/dd0156288cb6f8c4c3c7f259fcada5e1 to your computer and use it in GitHub Desktop.
TextField modded to support redux-form Field props
var React = require('react');
module.exports = React.createClass({
displayName: 'TextField',
propTypes: {
label: React.PropTypes.string.isRequired,
value: React.PropTypes.string.isRequired,
},
getDefaultProps: function() {
return {
value: ''
}
},
getStyles: function() {
return {
description: {
marginTop: '-5px',
color: '#777'
}
}
},
onChange: function(e){
var value = e.target.value;
this.props.input.onChange({
target: {
label: this.props.label,
value: value
}
});
},
getformClassNames: function(){
var e = this.props.meta.error;
var t = this.props.meta.touched;
var n = ['form-group'];
n = (t && e) ? n.concat('has-error') : n;
return n.join(' ');
},
render: function () {
var attribute = this.props.attribute;
var styles = this.getStyles();
return (
<div className={this.getformClassNames()}>
<label className="control-label">
{attribute.displayName || this.props.label}
</label>
<p style={styles.description}>
{attribute.description}
</p>
<textarea
name={this.props.input.name}
value={this.props.input.value}
onBlur={this.props.input.onBlur}
onChange={this.props.input.onChange}
onDrop={this.props.input.onDrop}
onFocus={this.props.input.onFocus}
type="text"
className="form-control"
rows="3"
placeholder={attribute.placeholder}
/>
{(this.props.meta.touched && (this.props.meta.error &&
<span className='help-block'>{this.props.meta.error}</span>))}
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment