1

I try to attach event handler to react bootstrap select component bootstrap select component.

class MyComponent extends React.Component {
  constructor(props) {
    super();
    this.state = {
      value: 'initial'
    };
  }
  handleSelect(value) {
    console.log(value);
    this.setState({
      value: value
    });
  }

  render() {
    return (
      <div>
        <div> selected value { this.state.value }</div>
        <FormControl
          componentClass="select"
          placeholder="select"
          onChange={this.handleSelect.bind(this)}
        >
          <option value="test" eventKey="select">select</option>
          <option value="asdas" eventKey="other">...</option>
        </FormControl>
      </div>
    );
  }
}

but in handleSelectinstead of clicked option value I get some Proxy object.

Here is CodePen showing the problem.

What is the proper way of attaching handlers to FormControl?

1 Answer 1

2

First argument in the onChange event handler is event object. You can access the selected value by looking at event target - evt.target.value:

handleSelect(evt) {
  console.log(evt.target.value);
  this.setState({
    value: evt.target.value
  });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.