Is there a way to limit Material UI TextFields of input type = file to accept only pdf?
Asked Answered
G

2

8

I am trying to make my input type=file to limit the user to only upload pdf.

I looked it up and saw that using accept attribute can help. But it is not working using material UI text fields.

Any solution I can try?

Grenadier answered 4/5, 2021 at 20:57 Comment(1)
you can use the accept attribute <input type="file" accept=".pdf">Crotchety
C
17

Have you tried this:

<TextField type={"file"} inputProps={{accept:"application/pdf"}}/>
Carburetor answered 4/5, 2021 at 21:2 Comment(4)
Great, just add type="file"Apheliotropic
In inputProps it works too, but TextField itself accepts type prop :)Apheliotropic
I wasn't sure if it accepted all the input typesCarburetor
Yeah, actually it accepts any valid HTML5 input type.Apheliotropic
D
1

<TextField type={"file"} inputProps={{accept:"application/pdf"}}/>

Disposal answered 26/12, 2022 at 9:7 Comment(1)
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now.Embow

© 2022 - 2024 — McMap. All rights reserved.