From b1770a9175f441f962662bdd9de50aaf5c28ca4c Mon Sep 17 00:00:00 2001 From: Michael Randers-Pehrson Date: Fri, 22 Aug 2014 09:11:03 -0400 Subject: [PATCH] Adding validation check to `handleSubmit`. Also adding `e.preventDefault()` and changing to plain `return`. --- scripts/example.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/example.js b/scripts/example.js index 87dfa40f..0d316b6e 100755 --- a/scripts/example.js +++ b/scripts/example.js @@ -89,13 +89,17 @@ var CommentList = React.createClass({ }); var CommentForm = React.createClass({ - handleSubmit: function() { + handleSubmit: function(e) { + e.preventDefault(); var author = this.refs.author.getDOMNode().value.trim(); var text = this.refs.text.getDOMNode().value.trim(); + if (!text || !author) { + return; + } this.props.onCommentSubmit({author: author, text: text}); this.refs.author.getDOMNode().value = ''; this.refs.text.getDOMNode().value = ''; - return false; + return; }, render: function() { return (