TimeField.js 1.9 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import cx from 'classnames';
import s from './CustomForm.scss';
import TimePicker from '../TimePicker'


class TimeField extends React.Component {
    constructor(props) {
        super(props);    
        this.timeChange=this.timeChange.bind(this);
    }
    static propTypes = {    
        displayName:PropTypes.string,
        field:PropTypes.object, 
        inlineFlag:PropTypes.bool,
        placeholder:PropTypes.string 
    } 
    static defaultProps={
        inlineFlag:false 
    }
    validationState(field){
        if(field.error&&field.touched){
            return 'error';
        }else if(field.touched)
            return ''; 
    }
    timeChange(value){
        const {field}=this.props;
        field.onChange(value);  
    }
    render(){  
        const {displayName,inlineFlag,field,placeholder}=this.props,self=this;  
        let validateState=this.validationState(field);
        return( 
            <div className={cx(s.field_wrap,'form-group',{
                'has-success':validateState=='success',
                'has-warning':validateState=='warning',
                'has-error':validateState=='error',
                'row':inlineFlag
            })}> 
                <label className={cx('control-label',{
                    'col-sm-3':inlineFlag
                })}>{displayName}</label>
                <div className={cx(s.input_wrap,{
                    'col-sm-9':inlineFlag
                })} > 
                    <TimePicker  className={cx('form-control',s.time_field_wrap)}  placeholder={placeholder} 
                    onChange={this.timeChange} value={field.value} ></TimePicker>
                    <span className={cx(s.input_help,'help-block')}><small>{field.touched?field.error:''}</small></span>
                </div>
            </div> 
        )
    }
}



export default TimeField;