DateField.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 = {
label:PropTypes.string,
placeholder:PropTypes.string,
field:PropTypes.object,
inlineFlag:PropTypes.bool,
}
componentDidMount(){
const {field,defaultValue}=this.props;
const {defaultDate}=this.state;
field.onChange(field.value||defaultValue||defaultDate);
}
render(){
const {inlineFlag,label,field,fieldConfig,defaultValue,placeholder}=this.props,self=this;
return(
<div className={cx(s.field_wrap,'form-group',field.touched&&field.error?'has-error':'',{
'row':inlineFlag
})}>
{label&&<label className={cx('control-label',{
'col-sm-3':inlineFlag
})}>{label}</label>}
<div className={cx(s.input_wrap,{
'col-sm-9':inlineFlag
})} >
<DatePicker onChange={field.onChange} placeholder={placeholder}
defaultValue={field.value||defaultValue||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;