In an html form, I have this select menu. It’s like a profile that a user can edit it later and change the values. Here is the FirstComponentcode that is rendering the form:
export const FirstComponent = React.createClass({
handleLanguageCode: function(langValue) {
this.setState({
language: langValue
});
},
renderField() {
return (
<div>
<SelectLanguage onSelectLanguage={this.handleLanguageCode} defValue={getValue()} />
</div>
);
}
)}
If the user wants to edit the form, getValue() will send the current value to SelectLanguage Component. The following is the code for this component:
import { DropdownList } from 'react-widgets';
export const SelectLanguage = React.createClass({
getInitialState: function(){
return{
value: '',
};
},
handleLangChange: function (val) {
var name = val.name
//this.props.onSelectLanguage(val.id); //???
//this.props.defValue(name); //???
//this.setState({defValue: name}); //???
//this.state.value = defaultVal //???
},
componentWillMount() {
this.componentWillReceiveProps(this.props);
},
componentWillReceiveProps(props) {
var def = this.props.defValue || 'eng';
this.setState({value:def});
},
render() {
const languages = [{"id": "eng", "name": "english"}, {"id": "swd", "name": "swedish"}] // it's a big json array!!
return (
<div >
<DropdownList
ref='dropdown'
data={languages}
valueField='id'
textField={item => item.name}
caseSensitive={false}
filter={this.filterLanguage}
value={this.state.value}
onChange={this.handleLangChange} />
</div>
);
}
});
The problem is when the user selects a new value from the dropdown menu, it doesn't update it!! It still shows the previous value. I don't know how to write the handleLangChange function to handle it. I tried several ways but couldn't get the result :/ Can anyone help me to fix it?