在我添加validateFields()
和规则之前,一切都运行得很好,现在我收到了一个错误TypeError: nameList.map is not a function
,我也在尝试使用async/awit,我不确定为什么会发生这种情况,之前的代码在没有validateFields()
的情况下工作得很好,另一方面我使用getFieldValue('categoryName')
来获取输入值,它在开始的时候工作得很好,然后值是空的。在我做了调查之后,我找不到任何线索。请谁来帮帮我。
updateCategory = () => {
//hide confirm box
this.formRef.current.formRef.current.validateFields(async (err, values) => {
if (!err) {
this.setState({
showStatus: 0,
});
const categoryId = this.category._id;
const categoryName = this.formRef.current.formRef.current.getFieldValue(
'categoryName',
);
//Reset fields to initialValues
this.formRef.current.formRef.current.resetFields();
//request to update category
const result = await reqUpdateCategory({ categoryId, categoryName });
if (result.status === 0) {
//reload display list
this.getCategorys();
}
}
});
};
发布于 2021-01-04 03:03:50
只是碰巧遇到了这一点,所以这主要是为后面的任何人准备的,但是validateFields
不接受函数作为参数。validatFields的签名是function (nameList, options)
。名称列表是要验证的字段的列表。
如果不提供参数,它将使用表单本身中的字段。我相信您在这里要做的是.validateFields().then(async(err, values)=> { ... }
,如下所示:
updateCategory = () => {
//hide confirm box
this.formRef.current.formRef.current.validateFields().then(async (err, values) => {
if (!err) {
this.setState({
showStatus: 0,
});
const categoryId = this.category._id;
const categoryName = this.formRef.current.formRef.current.getFieldValue(
'categoryName',
);
//Reset fields to initialValues
this.formRef.current.formRef.current.resetFields();
//request to update category
const result = await reqUpdateCategory({ categoryId, categoryName });
if (result.status === 0) {
//reload display list
this.getCategorys();
}
}
});
};
发布于 2021-10-12 04:04:06
请注意,从antd3->antd4迁移,validateFields
不再支持回调,您应该使用以下代码:
validateFields().then(callback)
https://stackoverflow.com/questions/64399070
复制相似问题