reactjs - React Textfield / redux 表单组件不允许写入
问题描述
表单渲染:
return (
<form onSubmit={handleSubmit}>
<Field
name="login"
component={RenderTextField}
label="Login"
/>
<Field
name="password"
component={RenderTextField}
label="Password"
/>
</form>
)
证实:
const RenderTextField = ({
label,
input,
meta: { touched, invalid, error },
...custom
},props) => {
const classes = useStyles();
return (
<TextField
label={label}
placeholder={label}
error={touched && invalid}
helperText={touched && error}
{...input}
{...custom}
/>
);
}
const validate = values => {
console.log(values);
const errors = {}
const requiredFields = [
'login',
'password',
]
requiredFields.forEach(field => {
if (!values[field]) {
errors[field] = 'Required'
}
})
if (
values.email &&
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)
) {
errors.email = 'Invalid email address'
}
return errors
}
我不知道错误在哪里,它只在我的验证中输入一次,我无法在我的文本字段中输入任何内容我正确导出了我的表单,我从 redux 表单文档中获得的验证我的 RenderTextField 也有人可以帮助我吗?
//
即使我没有点击它首先验证的文本字段并返回我,我的验证也会正常进行:
错误:
{登录名:“必填”,密码:“必填”}
但我不能在我的文本字段中写字,
我发现问题是:
{...input}
{...custom}
解决方案
推荐阅读
- android - /mobile/mobile 应用代码/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r/android/arch/lifecycle/livedata/core 的索引
- python - 使用烧瓶部署时,我必须在哪里复制文件 style.css?
- javascript - event.value 和 event.target.value 的区别
- jquery - 材料设计需要获得现有芯片的价值
- c++ - 多个`cin`没有给出正确答案
- python - 我不断收到“只有大小为 1 的数组可以转换为 Python 标量”,但我不知道为什么
- node.js - 如何使用 ExcelJS 在 NodeJS 中附加现有的 Excel 文件
- reason - 是否可以使用 ReasonReact 构建单个组件?
- javascript - 可以在 Express 应用程序中停止执行带有 return 语句的异步路由处理程序吗?
- excel - 即使值明显匹配,Excel 匹配函数也会导致错误