From a32276e400785fdeafdfb2685cd8154aa4a7cc38 Mon Sep 17 00:00:00 2001 From: petehunt Date: Mon, 3 Jun 2013 00:44:20 -0700 Subject: [PATCH] Fix bug in todomvc --- examples/todomvc/js/app.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/todomvc/js/app.js b/examples/todomvc/js/app.js index 336e424faa..8d83692eed 100644 --- a/examples/todomvc/js/app.js +++ b/examples/todomvc/js/app.js @@ -33,10 +33,10 @@ function cx(obj) { var TodoItem = React.createClass({ handleSubmit: React.autoBind(function() { - var val = this.refs.editField.getDOMNode().value.trim(); + var val = this.state.editText; if (val) { this.props.onSave(val); - this.refs.editField.getDOMNode().value = ''; + this.setState({editField: ''}); } return false; }), @@ -48,7 +48,16 @@ var TodoItem = React.createClass({ if (event.nativeEvent.keyCode === 27) { this.handleSubmit(); } + this.setState({editText: event.target.value}); }), + getInitialState: function() { + return {editText: this.props.todo.title}; + }, + componentWillReceiveProps: function(nextProps) { + if (nextProps.todo.title !== this.props.todo.title) { + this.setState(this.getInitialState()); + } + }, render: function() { return (
  • @@ -66,9 +75,9 @@ var TodoItem = React.createClass({