我正在尝试使用React Hook表单上传文件,并且使用了USECONTROLLER函数,并且我会遇到错误
我正在创建一个多部分形式,其中使用React Hook形式的USECORTOR方法。我声明默认值
const methods = useForm({
defaultValues: {
email: "",
course: "Enginering",
program: "B.tech",
mobielNumber: "",
dob: "",
gender: "",
cityName: "",
state: "",
file:"",
},
});
,但是我得到的文件值是null可以告诉我,如果我必须声明文件输入,以便我可以获得值。
我在那里看到了文件
文件输入输入将需要在应用程序级别进行管理 能够取消文件选择和filelist对象。
这些意味着我必须宣布它的地方。
I am creating a multipart form in which uses usecontrol method of react hook form . i declarer default value
const methods = useForm({
defaultValues: {
email: "",
course: "Enginering",
program: "B.tech",
mobielNumber: "",
dob: "",
gender: "",
cityName: "",
state: "",
file:"",
},
});
but i am getting file value is null can any one tell me were i have to declare file input so i can get value .
I seen documentation there they told
File typed input will need to be managed at the app level due to the
ability to cancel file selection and FileList object.
what these means where i have to declare it .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一天过后,我弄清楚了我们在使用USECONTROLLER发布文件时需要明确setValue的某些方式
,并且以某种方式 field 对象具有 value 的内部,它将得到e.target.value均为默认值,它类似于... fakepath/..不正确,因为文件在e.target.files内部上载
不包括 value ,因为usecontroller,因为 value 内部字段将导致错误如果与文件一起使用时,
当您提交时,您将看到filelist,如果不是 facepath 正如我所说
After a day I figure it out that some how we need to explicitly setValue when we post file with useController
And also somehow the field object has value inside of it, it will get e.target.value as default and it something like ...fakepath/.. which not true because files upload inside e.target.files
Don't include value inside as a result of useController because the value inside field gonna cause the error if it use together with files
When you submit it, you gonna see the FileList, if not or something like fakepath as i said you need to manually setValue to e.target.files