TextField.js 1.3 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';   
import cx from 'classnames';
import s from './reduxfields.scss'; 


class TextField extends React.Component {
    constructor(props) {
        super(props);  
        this.validationState=this.validationState.bind(this);
    }
    static propTypes = {    
        field:PropTypes.object,
        onChange:PropTypes.func,
        onKeyUp:PropTypes.func,
        placeholder:PropTypes.string
    } 
    static defaultProps={   
        placeholder:''
    }  
    validationState(field){
        if(field.error&&field.touched){
            return 'error';
        }else if(field.touched)
            return null;
        else
            return null;
    } 
    componentDidMount(){  
    }  
    componentWillReceiveProps(nextProps){   
    }
    componentDidUpdate(prevProps,prevState){  
    }
    componentWillUnmount() {  
        
    }  
    render(){       
        const {field,onChange,placeholder,onKeyUp}=this.props;
        // console.log(field)
        return (
            <div  > 
                <input onKeyUp={onKeyUp} type="text"  onChange={field.onChange} placeholder={placeholder} value={field.value}  /> 
                <div>{field.touched?field.error:''}</div>
            </div>
        ) 
    }
}



export default TextField;