Skip to content

Commit

Permalink
Use ref is bad practice -> update model with onChange (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwannT authored and mathieu-pousse committed Sep 5, 2016
1 parent afafb5e commit bbddd4b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions webapp/src/NewPlayerButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class NewPlayerButton extends Component {
this.state = {
boards: []
}

this.handleBoardChange = this.handleBoardChange.bind(this)
this.handlePlayerNameChange = this.handlePlayerNameChange.bind(this)
}

componentDidMount() {
//TODO use a react library for materialyzecss
this.listBoards()
}

Expand All @@ -26,8 +28,8 @@ class NewPlayerButton extends Component {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: this._nameinput.value,
board: this._boardinput.selectInput.value
name: this.name,
board: this.board
})
})
.then((response) => response.json())
Expand All @@ -43,24 +45,32 @@ class NewPlayerButton extends Component {
}


handlePlayerNameChange(event) {
this.name = event.target.value
}

handleBoardChange(event) {
this.board = event.target.value
}


render() {
return (
<div className="col s12">
<div className="input-field col s12 l5">
<input ref={(c) => this._nameinput = c} id="playerName" type="text" className="validate"/>
<input id="playerName" type="text" className="validate" onChange={this.handlePlayerNameChange}/>
<label htmlFor="playerName">Player name</label>
</div>
<div className=" col s8 l4">
<Input type='select' label="Board" ref={(c) => this._boardinput = c}>
<Input type='select' label="Board" onChange={this.handleBoardChange}>
{ this.state.boards.map((board) => <option value={board}>{ board }</option>) }
</Input>
</div>
<div className="input-field col s4 l3">
<a className="waves-effect waves-light btn light-blue" onClick={() => this.addPlayer() }>Add</a>
</div>
</div>
)
)
}
}

Expand Down

0 comments on commit bbddd4b

Please sign in to comment.