I want to store data in list with AutoComplete Component. User write text in AutoComplete Component and clicking on add Button data should stored in list and after that I want to clear AutoComplete Text.
But there is no method or properties to clear Input of AutoComplete.
Version :
0.15.0
I got it working by using setState on the searchText property with refs as in
import AutoComplete from 'material-ui/AutoComplete';
...
handleNewRequest(chosenRequest,idx){
if (idx>-1) //only allow selected items to be added
{
//do something with the chosenRequest, eg rest request
setTimeout(()=>{
this.refs[`autocomplete`].setState({searchText:''});
this.refs[`autocomplete`].focus();
}, 700);
}
}
and the render
render(){
return (<AutoComplete
ref={`autocomplete`}
hintText="Enter Some Tezt..."
dataSource={...}
onNewRequest={this.handleNewRequest.bind(this)}
fullWidth={true}
/>);
}
Duplicate of #2615
@itsjimbo Thanks! Your code solved my problem ;)
Simple if clear button is enabled
this.refs[
autocomplete ].getElementsByClassName('MuiAutocomplete-clearIndicator')[0].click();
Most helpful comment
I got it working by using setState on the searchText property with refs as in
and the render