Skip to content

Instantly share code, notes, and snippets.

@taylorlapeyre
Last active August 29, 2015 14:17
Show Gist options
  • Save taylorlapeyre/c21a69ec1ccb8bc20f35 to your computer and use it in GitHub Desktop.
Save taylorlapeyre/c21a69ec1ccb8bc20f35 to your computer and use it in GitHub Desktop.
var SelectThing = React.createClass({
getInitialState: function() {
return {
chosenFirstValue: "",
chosenSecondValue: ""
}
},
updateFirstSelectValue: function(e) {
var value = $(e.currentTarget).val();
if (this.state.secondSelectValue == "whatever") {
// do some logic
}
this.setState({
chosenFirstValue: value
})
},
updateSecondSelectValue: function(e) {
var value = $(e.currentTarget).val();
if (this.state.firstSelectValue == "whatever") {
// do some logic
}
this.setState({
chosenSecondValue: value
})
},
render: function() {
var firstSelectItems = this.props.collection1.map(function(item) {
return <option value={item}>{item}</option>;
});
var secondSelectItems = this.props.collection2.map(function(item) {
return <option value={item}>{item}</option>;
});
return (
<div class="select-thing">
<select onInput={updateFirstSelectValue}>
{firstSelectItems}
</select>
<select onInput={updateSecondSelectValue}>
{secondSelectItems}
</select>
</div>
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment