javascript - Mutliple event's to listen for in a input element (Reactjs) -
hello have input element this:
<input type="text" classname="form-control" placeholder="search for..." value={this.state.text} onchange={this.handletextchange} />
i have button beside onclick
make ajax call using input text search results.
what want not click event on pressing enter ajax call should go through tried this:
<input type="text" classname="form-control" placeholder="search for..." value=this.state.text} onchange={this.handletextchange} onkeydown={this.handleenter} />
but seizes work ideas's why?
remove e.preventdefault
handleenter: function (e) { if (e.keycode == 13) { var text = this.state.text.trim(); if(!text){ return; } this.props.ontextchange({ text: text }); } }, handletextchange: function (e) { this.setstate({ text : e.target.value }); },
Comments
Post a Comment