javascript - 如何在自定义组件中处理 onSubmit
问题描述
我的自定义组件有 onChange 事件,效果很好,但是当我尝试 onSubmit 时,它不起作用。不显示警报。
目前我的数据提供者从输入中获取所有值,除了我的自定义组件,我该怎么办?代码有什么问题?可以将此自定义组件中的数据传递到父表单吗?
父母形式:
export const smthEdit = props => (
<Edit {...props} title={<smthTitle/>} aside={<Aside />}>
<SimpleForm>
<DisabledInput source="Id" />
<TextInput source="Name" />
<ReferrenceSelectBox label="Socket" source="SocketTypeId" reference="CPUSocketType"></ReferrenceSelectBox>
<DateField source="CreatedDate" showTime
locales={process.env.REACT_APP_LOCALE}
disabled={true} />
</SimpleForm>
</Edit>
);
我的自定义组件(参考选择框):
handleSubmit(event) {
alert('smth');
}
render() {
return (
<div style={divStyle}>
<FormControl onSubmit={this.handleSubmit}>
<InputLabel htmlFor={this.props.label}>{this.props.label}</InputLabel>
<Select
multiple
style={inputStyle}
value={this.state.selectedValue}
onChange={this.handleChange}
>
{this.renderSelectOptions()}
</Select>
</FormControl>
</div>
);
}
解决方案
Error is change FormControl to form
<form onSubmit={(event) => this.handleSubmit(event)}>
<InputLabel htmlFor={this.props.label}>{this.props.label}</InputLabel>
<Select
multiple
style={inputStyle}
value={this.state.selectedValue}
onChange={this.handleChange}
>
{this.renderSelectOptions()}
</Select>
</form>
推荐阅读
- amazon-sagemaker - 如何使用 sagemaker java API 调用端点?
- javascript - 文件夹级脚本引用文档级脚本
- python - 到每个质心的 Kmeans 欧几里得距离避免从 DF 的其余部分拆分特征
- c# - 使用 MOQ 和 C# 模拟接口并调用原始实现方法
- c# - 重构重复的 EntityFramework 的 Fluent API 语句
- excel - 在 VBA 中以编程方式删除文件时遇到问题
- android - Android YouTube Player API 显示错误:ERROR_CONNECTING_TO_SERVICE
- sqlalchemy - 如何查询多个多态继承表上的关系?
- python-3.x - Tkinter .see() 方法不在文本框 1 中滚动。它只是在动态创建的最后一个文本框中滚动
- flutter - Flutter 重绘应用栏