RplyTextarea.js
2.3 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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './Custom.scss';
import { Button,FormGroup,ControlLabel,FormControl,HelpBlock} from 'react-bootstrap';
class RplyTextarea extends React.Component {
constructor(props) {
super(props);
this.changeMessage=this.changeMessage.bind(this);
this.sendComment=this.sendComment.bind(this);
this.state={
message:'',
errors:''
}
}
static propTypes = {
sendComment:PropTypes.func,
use:PropTypes.object
}
static defaultProps={
use:{
user_image:"/img/user.jpg"
}
}
changeMessage(e){
this.setState({
message:e.target.value,
errors:''
})
}
sendComment(){
const {message}=this.state;
const {sendComment}=this.props;
console.log(message);
if(!message){
this.setState({
errors:'此项不能为空'
})
}else if(!message.replace(/(^\s*)|(\s*$)/g,'')){
this.setState({
errors:'此项不能为空格'
})
}else{
sendComment(message.replace(/(^\s*)|(\s*$)/g,''));
this.setState({
message:''
})
}
}
render(){
const {message,errors}=this.state;
const {use}=this.props;
return(
<div className={cx(s.rply_textarea_wrap)}>
<a className={cx(s.member_image)}><img src={use.user_image} /></a>
<div className={cx(s.member_msg_input)}>
<FormGroup validationState={errors?"error":null}>
<FormControl componentClass="textarea" onChange={this.changeMessage} value={message} />
<HelpBlock>{errors}</HelpBlock>
</FormGroup>
<div className={cx(s.individual_submit,'clearfix')} style={{marginTop:'10px'}}>
<p className={cx(s.c_gray,'fl')}>注:你可以按enter进行换行</p>
<a className={cx('fr',s.submit_btn)} onClick={this.sendComment} >发布评论</a>
</div>
</div>
</div>
)
}
}
export default RplyTextarea;