make form dropdowns work

This commit is contained in:
ronreg-ribdev 2020-05-31 05:07:42 -07:00
parent 7e379ba576
commit 4fd6a5ee25

View File

@ -13,8 +13,18 @@ export class Root extends Component {
}); });
} }
action() { stationSearch() {
console.log("Clickin'"); console.log("Searching");
}
changeStation(evt) {
const target = evt.target.name;
const value = evt.target.value;
if (target === "fromStation") {
this.setState({fromStation: value});
} else if (target === "toStation") {
this.setState({toStation: value});
}
} }
renderStationOptions() { renderStationOptions() {
@ -27,16 +37,17 @@ export class Root extends Component {
} }
renderStationForm() { renderStationForm() {
return (<form name="bartSearch"> return (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
From: From:
<select value={this.state.fromValue || ""}> <select name="fromStation" value={this.state.fromStation || ""} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() } { this.renderStationOptions() }
</select> </select>
<br/> <br/>
To: To:
<select value={this.state.toValue || ""}> <select name="toStation" value={this.state.toStation || ""} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() } { this.renderStationOptions() }
</select> </select>
<input type="submit" value="Search"/>
</form>); </form>);
} }
@ -60,10 +71,6 @@ export class Root extends Component {
<div className="searchsidebar" style={{gridColumn: "2", gridRow: "2"}}> <div className="searchsidebar" style={{gridColumn: "2", gridRow: "2"}}>
Search scheduled trains: Search scheduled trains:
{ this.renderStationForm() } { this.renderStationForm() }
<form name="bartSearch">
From:
</form>
<button onClick={this.action.bind(this)}>Search</button>
</div> </div>
</div> </div>
</div> </div>