Skip to content

How to use input type file in Form? #2137

Closed Answered by zeekrey
zwl1619 asked this question in Q&A
Discussion options

You must be logged in to vote

I encountered the same issue, and I've submitted my PR to address it. You can find it here: GitHub PR. To resolve the problem, follow these steps:

When utilizing <Input type="file" /> alongside React Hook Form, it is important to have an uncontrolled input. You can achieve this by simply passing the onChange handler to the onChange prop of the input element.

<FormField
  control={form.control}
  name="picture"
  render={({ field: { value, onChange, ...fieldProps } }) => (
    <FormItem>
      <FormLabel>Picture</FormLabel>
      <FormControl>
        <Input
          {...fieldProps}
          placeholder="Picture"
          type="file"
          accept="image/*, application/pdf"
          o…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
6 replies
@6abotage
Comment options

@sp88011
Comment options

@vamshimorlawar
Comment options

@sahmed007
Comment options

@jrnxf
Comment options

Answer selected by zwl1619
Comment options

You must be logged in to vote
2 replies
@tanvir0604
Comment options

@tanvir0604
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet