gpt4 book ai didi

reactjs - Redux表格: Set error to a field without submitting the form

转载 作者:行者123 更新时间:2023-12-02 21:14:35 25 4
gpt4 key购买 nike

我有一个正在从 API 加载数据的表单。如果 api 调用中发生一些错误,我会尝试手动设置该字段的错误。

// This is the input that I'm trying to set the error message
<Field
name="username"
component={CustomCombobox}
/>

这里我试图在 catch block 中设置一个错误。

try {
const { data } = await UserService.getUser();
} catch (e) {
// here I'm trying to set an error to "username" field
stopSubmit('myFormName', { username: 'Something wrong happened.' })
}

但是问题就在这里。我没有提交表单,因此 stopSubmit 不起作用。我只是从 API 接收数据来填充选项,如果发生一些错误,我想手动设置错误。

最佳答案

This website has some examples on form validation如果您尝试在提交表单之前对用户名进行检查,则可以对字段的值运行 API 调用,然后在函数失败时显示错误。

也许这不是你要找的/我误解了

关于reactjs - Redux表格: Set error to a field without submitting the form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49628408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com