DateField.js
2.0 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './form.scss';
import moment from 'moment';
import {Form,DatePicker} from 'antd';
const FormItem = Form.Item;
class DateField extends React.Component {
constructor(props) {
super(props);
this.dateChange=this.dateChange.bind(this);
this.state={
value:''
}
}
static propTypes = {
label:PropTypes.string,
options:PropTypes.object
}
static defaultProps={
}
componentDidMount(){
// const {field={}}=this.props;
// const value=field.value?moment(field.value).format():'';
// field.onChange(value);
}
componentWillReceiveProps(nextProps){
// const {field={}}=nextProps;
// const value=field.value?moment(field.value).format():'';
// if(this.props.field.value!=field.value){
// field.onChange(value);
// }
}
dateChange(value, dateString){
const {field={}}=this.props;
if(value){
// console.log(moment(value).format());
field.onChange(moment(value).format());
}else{
field.onChange('');
}
}
render(){
const {label,options,name,tabular,field={}}=this.props;
const tabularStyle=tabular?{width:"100%"}:{};
// console.log('@@@@@@@@@@@@',field.value)
const value=field.value?moment(field.value).format():null;
console.log(value)
return(
<FormItem
label={label}
labelCol={{ span: 6 }}
wrapperCol={{ span: tabular?24:14 }}
required={options.is_required}
validateStatus={null}
help=""
>
<DatePicker name={name} style={{display:'inline-block',...tabularStyle}} value={value} placeholder={options.tooltip} onChange={this.dateChange} ></DatePicker>
</FormItem>
)
}
}
export default DateField;