getInitialState: function() {
return {
name: "",
description: "",
formValid: false,
errors: {}
};
},
handleChange: function(e) {
this.setState({
"name": ReactDOM.findDOMNode(this.refs.name).value,
"description": ReactDOM.findDOMNode(this.refs.description).value
});
var formValid = true;
if (this.state.name == "") { formValid = false; }
if (this.state.description == "") { formValid = false; }
this.setState({ "formValid": formValid });
},
And in my render()
:
<div className="form-group">
<label for="communityName" className="col-sm-3 control-label">Community Name</label>
<div className="col-sm-9">
<input ref="name" onChange={this.handleChange} type="text" className="form-control" id="communityName" />
</div>
</div>
<div className="form-group">
<label for="communityAbout" className="col-sm-3 control-label">About</label>
<div className="col-sm-9">
<textarea ref="description" onChange={this.handleChange} className="form-control" id="communityAbout" rows="3"></textarea>
</div>
</div>
<button disabled={!this.state.formValid} type="submit" className="btn btn-sm btn-primary">Create</button>
When I type in values in either input or clear out the inputs, the button changes it’s state one more ‘change’ event than it should.
What am I doing wrong? Why is the component always ‘one step behind’ what it should be?
I’m following this simple example and I don’t see why the example works as expected, and this doesn’t. http://jsbin.com/fitiha/8/edit?js,output