ReadonlyForm.js
1.8 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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './ReadonlyForm.scss';
class ReadonlyForm extends React.Component {
constructor(props) {
super(props);
this.state={
sections:[]
}
}
static propTypes = {
formDefind:PropTypes.object,
record:PropTypes.object
}
componentWillMount(){
const {formDefind:{items}}=this.props;
if(items&&items.length>0){
this.setState({
sections:items
})
}
}
componentDidMount(){
}
renderFields(fields){
const {record}=this.props,self=this;
return fields.map((field,i)=>{
const options=JSON.parse(field.options);
const fieldType=field.type;
const fieldKey='lookup'==fieldType?field.name:field.name;
return (
<dl key={i} className={cx('dl-horizontal',s.item_wrpa)}>
<dt className={cx(s.item_lable)}>{field.display_name}</dt>
<dd className={cx('text-left',s.item_value)}>{record[fieldKey]}</dd>
</dl>
)
})
}
renderSections(){
const {sections}=this.state,self=this;
if(sections.length>1){
return sections.map((section,i)=>{
return(
<fieldset key={i}>
<legend>{section.display_name}</legend>
{self.renderFields(section.fields)}
</fieldset>
)
});
}else if(sections.length==1){
return this.renderFields(sections[0].fields);
}
}
render(){
const {formDefind,record}=this.props;
return (
<div className={cx('custom_form_wrap')}>
{this.renderSections()}
<div className={cx('bottom_wrap')}></div>
</div>
)
}
}
export default ReadonlyForm;