react hook form and MUI file input #8052
Replies: 2 comments 1 reply
-
By spreading By doing <Controller
name="photoIdPath"
control={control}
render={({ field }) => (
<TextField
{...field}
type="file"
onChange={(e: any) => {
+ setValue("photoIdPath", e.target.files[0].name);
+ field.onChange(e.target.files);
}}
/>
)}
/> you first assign the filename value to your |
Beta Was this translation helpful? Give feedback.
-
there is a way to upload the picture and get the name of the file with the onChange ? |
Beta Was this translation helpful? Give feedback.
-
I am using RHF and MUI file input, and have have the below error. I have been googled but still cannot fix it. Can anyone help me?
This is my Controller
<Controller name="photoIdPath" control={methods.control} render={({ field }) => ( <TextField {...field} variant="standard" label="Photo of ID" margin="dense" type="file" fullWidth onChange={(e: any) => { methods.setValue('photoIdPath', e.target.files[0].name); field.onChange(e.target.files); }} InputLabelProps={{ shrink: true, }} error={!!methods.formState.errors.photoIdPath} helperText={methods.formState.errors.photoIdPath ? methods.formState.errors.photoIdPath?.message : ''} /> )} />
And here is the error
Thank you
Beta Was this translation helpful? Give feedback.
All reactions