【发布时间】:2021-03-24 07:35:50
【问题描述】:
对不起,如果标题令人困惑。
基本上我有一个包含单个输入的表单,其中包含伪装成图标的类型文件
我希望在选择文件时提交表单,但我不知道如何使用输入 onChange 事件调用表单提交(我什至不确定这是否是适当的方法)。
代码如下:
<Form onSubmit={handleSubmit((data) => updateProfilePicture(data))}>
<IconButton
component='label'
htmlFor='image-input'
style={{
position: "absolute",
bottom: "0",
right: "0",
backgroundColor: "#eee",
}}
>
<Input
type='file'
id='image-input'
name='file'
style={{ display: "none" }}
inputRef={register}
/>
<PhotoCameraIcon style={{ fontSize: "25px" }} />
</IconButton>
</Form>
如下图:
注意:有两种形式,一种用于图像,一种用于数据,我不想通过“更新”按钮来处理,否则它只会是一种形式,我不会有这个问题
【问题讨论】:
标签: reactjs