Skip to content

Commit 4c1071d

Browse files
committed
Merge pull request reactjs#2 from michaelrp/patch-1
Adding validation check to `handleSubmit`.
2 parents b13626d + b1770a9 commit 4c1071d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

scripts/example.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ var CommentList = React.createClass({
8989
});
9090

9191
var CommentForm = React.createClass({
92-
handleSubmit: function() {
92+
handleSubmit: function(e) {
93+
e.preventDefault();
9394
var author = this.refs.author.getDOMNode().value.trim();
9495
var text = this.refs.text.getDOMNode().value.trim();
96+
if (!text || !author) {
97+
return;
98+
}
9599
this.props.onCommentSubmit({author: author, text: text});
96100
this.refs.author.getDOMNode().value = '';
97101
this.refs.text.getDOMNode().value = '';
98-
return false;
102+
return;
99103
},
100104
render: function() {
101105
return (

0 commit comments

Comments
 (0)