I have followed this documentation and have created a select tag with react.
I have edited this question, If I use className="browser-default" in select it works fine. But for materialize select it is not working.
onChange event is not working in my case. The function doesn't get called.
import React from 'react';
class Upload extends React.Component{
constructor(props){
super(props);
this.state={
degree:''
}
this.upload=this.upload.bind(this);
this.degreeChange=this.degreeChange.bind(this);
}
componentDidMount() {
$('select').material_select();
}
degreeChange(event){
this.setState({degree:event.target.value});
console.log(this.state.degree);
}
upload(){
alert(this.state.degree);
}
render() {
return (
<div className="container">
<form onSubmit={this.upload}>
<div className="input-field col s4">
<select value={this.state.degree} onChange={this.degreeChange}>
<option value="" disabled>Choose Degree</option>
<option value="B.E">B.E</option>
<option value="B.Tech">B.Tech</option>
</select>
</div>
<div className="row center-align">
<input className="waves-effect waves-light btn centre-align" type="submit" value="Submit"/>
</div>
</form>
</div>
);
}
}
I don't get any error here, but my degreeChange function doesn't get called. I am not getting what my error is.