When i try to clear the value of the TextField passing searchText props, after select one item from the menu, the value want change.
I'm using the onNewRequest callback, but it's called before setState with selected value.
Also trying to change searchText props with a setTimeout (after the setState function has been called), the check in componentWillReceiveProps doesn't let the state to be changed.
You can see that the value doesn't change as its searchText props.
I'm having the same issue in the 0.15.0 release. I'm encountering this under slightly different circumstances where I was trimming the text in searchText after selection and it works but then something seems to overwrite it and the entire selected text comes back. I see something similar when I try to completely clear the field. The field is cleared temporarily and then the value selected from the dropdown returns.
I've created a simple example using the example code from the documentation. This will first clear the control then write back the selected value.
any further action on this issue? Clearing the display value after selecting seems quite important, if the auto complete component is used as a search box
As a workaround I do
const autoComplete = <your ref to AutoComplete>
setTimeout( () => autoComplete && autoComplete.setState({ searchText: "" }), 500 )
in the callback. In this case it works.
@priezz Thanks a lot man. Spent a whole day trying to figure this out.
It should be fixed now. The setTimeout hack should no longer be needed.
Try this :
this.setState({ searchText: "\r" });
because I think the function should test the length of the string (BUG ?)
I could use some help,
I am able to clear the value after submit by clearing the Form. The previously selected item, however, still remains in the text field. I need to clear this since I am loading the list dynamically and 'refetching' after every submit. See code below:
<Autocomplete
onChange={(event, selectedValue) => setFieldValue('SerialNumber', selectedValue, true)}
clearText = 'Clear'
options={getSerials.serials.map((routers) => serials.SerialNumber)}
autoComplete
openOnFocus
noOptionsText = 'No serial number to match your search'
renderInput={(params) => (
<TextField
{...params}
label="Search/Enter serial number"
required
name="SerialNumber"
helperText={
errors.SerialNumber || null
}
variant="outlined"
value={values.SerialNumber}
SelectProps={{ native: true }}
/>
)}
/>
@TheCodeNinja254 Look into how you can control the value of the component, alternatively, you can ask on Stackoverflow.
Most helpful comment
It should be fixed now. The
setTimeouthack should no longer be needed.