I have i dynamic form and having issue with Autocomplite component from material-ui when i connected with react-final-form-arrays, cant get the selected item value
here is form code
<Field
name={`${name}`.product}
list={products}
component={AutocompleteField}
label={'Products'}
/>
function ProductSelectField({list, label, dealer_id, stock_id, all_stocks, input, ...rest}) {
const {name, onChange, ...restInput} = input;
const [value, setValue] = useState([]);
const [inputValue, setInputValue] = useState('');
const getProducts = (event, newValue) => {
setValue(newValue);
}
return (
<Autocomplete
{...rest}
id="product"
options={list}
getOptionLabel={(option) => option.name}
defaultValue={list[0]}
onChange={getProducts}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
renderInput={(params) =>
<TextField
{...restInput}
{...params}
label={label}
variant="outlined"
/>
}
/>
);
}
Without any extra info or code box to go off of, it seems that you are not invoking the input's
onChangehook to update the fields state. In your Autocompleteprop.onChange, you are invoking thegetProductshook but not where are you passing the value to theonChangehook.These Docs on React-Final-Form shows you what the
inputprop passes down and it shows how it does all the work for you.However, I use the Autocomplete from material-ui as well and understand you want to control the local state at the same time. Refactor your
getProductshook to update both.