Skip to content

Instantly share code, notes, and snippets.

@mrudangshah
Last active December 4, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrudangshah/ed86f242e4be6a57cc2eb85fa254b2eb to your computer and use it in GitHub Desktop.
Save mrudangshah/ed86f242e4be6a57cc2eb85fa254b2eb to your computer and use it in GitHub Desktop.
I am getting console log for the *value* attr of `option` tag, but it is giving me an `undefined` for *data* attr of it's console log as i am doing the same thing for both so why the data attr is undefined ?
import { usersContext } from '../../Context';
class UserssField extends React.Component {
constructor (props) {
super(props);
}
selectUsers(e) {
var options = e.target.options;
var value = ''; var data = '';
for (var i = 0, l = options.length; i < l; i++) {
if (options[i].selected) {
console.log(options[i])
value = options[i].value;
data = options[i].data;
}
}
usersContext._currentValue.selectedValue = value;
usersContext._currentValue.selectData = data;
console.log(usersContext._currentValue.selectedValue);
console.log(usersContext._currentValue.selectData);
}
render () {
return (
<div className="form-group">
<select className="form-control" onChange={this.selectUsers} >
<option value="5e0fd754391c1207d689e8" data="john">john</option>
</select>
</div>
);
}
}
export default UserssField;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment