We use React, Material-UI, Formik and an Autocomplete + Textfield with the multiple tag.
<Autocomplete
disableClearable
disabled={!canEdit || readonly}
filterSelectedOptions
id={name + 'Property'}
multiple
onChange={handleChange}
options={options}
value={selected}
renderTags={(value: string[], getTagProps) =>
value.map((option: string, index: number) => <Chip {...getTagProps({ index })} key={option} variant="outlined" label={option} />)
}
renderInput={(params) => (
<TextField
{...params}
error={Boolean(errorMessage)}
helperText={errorMessage}
label={label ? intl.formatMessage({ id: label, defaultMessage: label }) : null}
margin="dense"
SelectProps={{ autoWidth: true }}
style={inputStyle}
sx={{ my: 0.6 }}
variant={'standard'}
/>
)}
/>
onChange function is defined in parent component as follow:
const handleChange = (e: React.ChangeEvent<any>) => {
formik.handleChange(e);
};
I expect to have the corresponding formik value set to the selected option(s), but it's not the case.
It works fine for all other type of fields but multiple select doesn't handle well the value change. How can I proceed to handle properly the change of the values in the multiple select?
Thanks