DateField.js 1.9 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom'; 
import moment from 'moment'; 
import {DatePicker} from '../custom';
import cx from 'classnames';
import s from '../FormRender.scss';


class DateField extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            defaultDate:moment().format()
        }    
    }
    static propTypes = {    
        formField:PropTypes.object,
        field:PropTypes.object,
        fieldConfig:PropTypes.object,
        validateState:PropTypes.string,
        inlineFlag:PropTypes.bool,

    } 
    componentDidMount(){
        const {field,defaultValue}=this.props;
        const {defaultDate}=this.state; 
        // field.onChange(defaultValue||defaultDate);
    }
    render(){  
        const {validateState,inlineFlag,formField,field,fieldConfig,defaultValue}=this.props,self=this; 
        const options=JSON.parse(formField.options);  
        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
                })}>{formField.display_name}</label>
                <div className={cx(s.input_wrap,{
                    'col-sm-9':inlineFlag
                })} > 
                    <DatePicker onChange={field.onChange} placeholder={options.tooltip} 
                    defaultValue={defaultValue||field.initialValue||this.state.defaultDate} config={fieldConfig}/> 
                    <span className={cx(s.input_help,'help-block')}><small>{field.touched?field.error:''}</small></span>
                </div>
            </div>   
        )
    }
}



export default DateField;