Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e.target.value reflects <select value={}> not <option value={}> in Chrome on Windows 10 #5641

Closed
felixakiragreen opened this issue Dec 10, 2015 · 10 comments
Labels
Component: DOM Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@felixakiragreen
Copy link

Just a note, it works perfectly fine on earlier versions of Windows and Mac OS X

code:

var Test = React.createClass({
  getInitialState: function() {
    return { value: '1' };
  },

  onChange: function(e) {
    this.setState({value: e.target.value})
    console.log(e.target.value)
  },

  render: function() {
    return (
      <div>
        <select value={this.state.value} onChange={this.onChange}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
      </div>
    );
  }
});

Whenever the onChange is triggered, the e.target.value is 1. I'm assuming this is because that is the value starts with. And any changes do not correctly change the value.

@conorhastings
Copy link

do you know what version of chrome this is?

@rmdort
Copy link

rmdort commented Dec 11, 2015

Your onChange handler is wrong

Use this

<select value={this.state.value} onChange={this.handleChange}>

@felixakiragreen
Copy link
Author

That was just example code. It works fine on Mac and earlier versions of Windows. Latest version of Chrome.

@univerio
Copy link

+1

I'm seeing this as well, but it doesn't reproduce in an isolated jsfiddle for me. Weird.

@univerio
Copy link

Some more details. I was able to make the issue reproduce reliably by adding an onClick handler that alters state:

var Test = React.createClass({
  getInitialState: function() {
    return { value: '1' };
  },

  onChange: function(e) {
    this.setState({value: e.target.value});
    console.log(e.target.value);
  },

  onClick: function(e) {
    this.setState({visible: true});
  },

  render: function() {
    return (
      <div>
        <select value={this.state.value} onChange={this.onChange} onClick={this.onClick}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
      </div>
    );
  }
});

http://codepen.io/anon/pen/KVdzjR

This reproduces in Chrome 47 on Windows and Linux, but not OS X, nor does it reproduce on Chrome 46 on any platform.

@jmandel
Copy link

jmandel commented Dec 24, 2015

I can confirm that I see the same behavior on Chrome 47 (on linux). My first selection (when initial value is null) works, and then subsequent selections fail to update the value.

@duoduoin
Copy link

duoduoin commented Jan 4, 2016

I found the same issue in latest Chrome 47. Is there any work around?

@gaearon
Copy link
Collaborator

gaearon commented Oct 3, 2017

Is this still an issue?

@gaearon gaearon added Component: DOM Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Oct 3, 2017
@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

I’ll assume this was a transient Chrome bug that was later fixed.
If it still occurs please file a new issue.

@gaearon gaearon closed this as completed Oct 4, 2017
@zedtux
Copy link

zedtux commented Jul 17, 2019

I'm facing this issue on Safari 12. I'm receiving the selected option text instead of the selected option value, which is annoying.

I'm using the code from the reactjs documentation.

Update

Actually I had an <option> with a null value. In this case, its text is returned instead of null. Putting a blank string fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: DOM Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

8 participants