I'm trying to build a reusable input file as per below.
function InputFileControl({ control, name, initialValue, ...rest }) {
const {
field: { ref, ...inputProps },
fieldState: { invalid, error, isTouched },
} = useController({
name,
control,
rules: { required: true },
defaultValue: initialValue,
})
return (
<StyledGrid>
<Grid item container>
<input {...inputProps} inputRef={ref} {...rest} />
</Grid>
<Collapse in={invalid}>
<Grid item container>
<StyledAlert severity="error">{error && error.message}</StyledAlert>
</Grid>
</Collapse>
</StyledGrid>
)
}
For usage, where my form is declared, this is how i'm using it:
<InputFileControl control={control} name="file" type="file" />
Unfortunately, It is not working. When i submit the form, the file is only the path. There is no files[0] to manage.
What can I try next?