I have one problem in my react code.
I use Material-ui and redux-form. I have select input like and after change this select i should reset value in . I use action 'change' from react-form and set value for textfield. But label in still remains. Can i clear or reset value in ?
<Autocomplete options={list} getOptionLabel={option => option.name} onInputChange={onChange} onChange={onChangeAutoComplete} noOptionsText='Нет доступных вариантов' loadingText='Загрузка...' openText='Открыть' renderInput={params => ( <Field {...params} label={label} name={fieldName} variant="outlined" fullWidth component={renderTextField} className={classes.textField} margin="normal" /> )} />
To hide browser autocomplete with React Material UI Autocomplete and TextField, we can set inputProps. autocomplete to 'off' . We set inputProps. autoComplete to 'off' in the renderInput function to disable browser autocomplete in the text field.
The autocomplete is a normal text input enhanced by a panel of suggested options.
Using hooks on the value prop breaks the functionality of the autocomplete component ( at least for me ). Using class, and setting the local state is the same.
Luckily it is a react component, so it have a "key" prop. When the key prop changes, the component is re-rendered with the default values ( which is an empty array since nothing is selected). I used hooks in the parent component and passed the values to the key prop, whenever reset is needed.
<Autocomplete key={somethingMeaningful} // Bool, or whatever just change it to re-render the component //...other props />
Hope this helps!
use value
in your <Autocomplete />
like this:
<Autocomplete value={this.state.value} //insert your state key here //...other props />
Then clear state of that key, to clear the autocomplete field value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With