CheckPicker.js
2.1 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
75
76
77
78
79
80
81
82
import React,{PropTypes} from 'react';
import {Table,ButtonGroup,Button,Modal,OverlayTrigger,Input,FormControls,Grid,Row,Col} from 'react-bootstrap';
import Select from 'react-select';
import 'react-select/dist/react-select.css';
import cx from 'classnames';
import s from './FormRender.scss';
class CheckPicker extends React.Component {
constructor (props, context) {
super(props, context);
}
static propTypes={
onChange: PropTypes.func,
choices:PropTypes.array,
values:PropTypes.array,
multi:PropTypes.bool,
error:PropTypes.bool,
disabled:PropTypes.bool,
}
changeCheck(value, e){
const {multi} = this.props;
console.log(multi);
console.log(value);
console.log(e);
this.props.onChange(value, multi);
}
render(){
const {multi,values, choices}= this.props;
console.log(choices);
const self = this;
if(multi){
return(
<div>
{values.map((value,index)=>{
const checked=choices.indexOf(value)==-1?false:true;
return(
<Row key={index}>
<label>
<input type="checkbox" checked={checked} onChange={self.changeCheck.bind(self, value)}/>
<span>{value}</span>
</label>
</Row>
);
})
}
</div>
);
}
else{
let choiced = '';
if(choices.length>0){
choiced = choices[0];
}
return(
<div className={cx(s.checkbox_group_wrap)}>
{
values.map((value,i)=>{
return (
<div key={i} className={cx(s.checkbox_wrap,'checkbox')}>
<label >
<input name="radio" type="radio" checked={(choiced+"")==value} value={value} onChange={self.changeCheck.bind(self,value)} />
<span>{value}</span>
</label>
</div>
);
})
}
</div>
);
}
}
}
export default CheckPicker;