DecimalField.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
68
69
70
71
72
73
74
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './form.scss';
import {Form,InputNumber} from 'antd';
const FormItem = Form.Item;
class TextField extends React.Component {
constructor(props) {
super(props);
this.validateField=this.validateField.bind(this);
this.getHelp=this.getHelp.bind(this);
}
static propTypes = {
label:PropTypes.string,
options:PropTypes.object,
tabular:PropTypes.bool,
field:PropTypes.object,
help:PropTypes.string,
inputStyle:PropTypes.object
}
static defaultProps={
tabular:false,
help:'',
inputStyle:{}
}
validateField(){
const {field={}}=this.props;
if(field.error&&field.touched){
return 'error';
}else if(field.touched&&!field.error)
return 'success';
else{
return null;
}
}
getHelp(){
const {help,field={}}=this.props;
if(field.touched){
return field.error;
}else if(help){
return help;
}else{
return "";
}
}
componentDidMount(){
}
componentWillReceiveProps(nextProps){
}
render(){
const {label,options,name,tabular,field={},inputStyle}=this.props;
// console.log('年龄年龄年龄年龄',field)
// const value=field.value?field.value:0;
return(
<FormItem
label={label}
labelCol={{ span: 6 }}
wrapperCol={{ span: tabular?24:14 }}
required={options.is_required}
validateStatus={this.validateField()}
help={this.getHelp()}
>
<InputNumber name={name} value={field.value} onChange={field.onChange} style={{display:'inline-block',...inputStyle}} placeholder={options.tooltip} size="default" />
</FormItem>
)
}
}
export default TextField;