Last active
December 4, 2019 14:06
-
-
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 ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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