i try to remove the textContent at MUI Custom Auto complete, the value already deleted but not with the text
heres my snippets code,
<form onSubmit={handleSubmit(onSubmit)}>
{fields.map((item, index) => (
<>
<Controller
name={`data[${index}].MasterProductId`}
control={control}
rules={{ required: true }}
render={({ field: { value, onChange } }) => (
<CustomAutocomplete
key={index}
options={OptionsGroup(masterDataProduct, 'category')}
id='autocomplete-grouped'
groupBy={option => option.category}
getOptionLabel={option => option.name || ''}
onChange={(event, newValue) => {
onChange(+newValue?.id)
}}
renderInput={params => (
<CustomTextField
value={item.MasterProductId}
{...params}
error={Boolean(errors?.data?.[index]?.MasterProductId)}
{...(errors?.data?.[index]?.MasterProductId && {
helperText: errors?.data?.[index]?.MasterProductId.message
})}
label='Pilih produk'
/>
)}
/>
)}
/>
<IconButton onClick={() => deleteItem(index)} sx={{ color: 'text.primary' }}>
<Icon icon='tabler:trash' />
</IconButton>
<>
)
</form>
using useForm and useFieldArray
const {
control,
handleSubmit,
formState: { errors },
setError,
setValue
} = useForm({
mode: 'onChange',
resolver: yupResolver(schemaNew)
})
const { fields, remove, append } = useFieldArray({
control,
name: 'data'
})
then this is my fn for remove
const deleteItem = itemIndex => {
remove(itemIndex)
}
I already do useState for the fields and re render using useEffect but the text not change, but the value is deleted. I confuse using control and miui render the component not update when the field is updated. I try to find how to clear value for the CustomTextField but i didnt get it
Dendi Joil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.