Answer the question
In order to leave comments, you need to log in
Why is the selected value lost in SelectField (material-ui) when updating data?
There is such a component
class Dropdown extends Component {
constructor(props) {
super(props)
this.state = {value: this.props.value}
this.renderMenuItems = this.renderMenuItems.bind(this)
}
renderMenuItems(accounts) {
return accounts.map((account) => (
<MenuItem
key={account.id}
insetChildren={true}
primaryText={<this.props.template {...account} />}
value={account}
/>
));
}
render() {
const {value} = this.props;
return (
<div className="transaction-dropdown">
<Translate className="dropdown-title" value={_.get(this.props, 'title', null)}/>
<div className="dropdown-content">
<SelectField
errorText={this.props.error}
value={value}
fullWidth={true}
onChange={(e, index, item) => {
this.setState({value: item})
this.props.select(item)
}}>
{this.renderMenuItems(this.props.data || [])}
</SelectField>
</div>
</div>
)
}
}
export default Dropdown
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question