我在react-redux应用程序中的提交操作如下
<form onSubmit={handleSubmit(this.onFormSubmit.bind(this))}>
<Field
name="username"
lable="Username"
type="text"
component={ renderField }
/>
<Field
name="email"
type="email"
lable="Email"
component={ renderField }
/>
{console.log("cheki...",error)}
hahahaah{error}
{error && <strong>{error}</strong>}
<Field
name="password"
type="password"
lable="Password"
component={ renderField }
/>
<Field
name="confirm_password"
type="password"
lable="Confirm Password"
component={ renderField }
/>
<button type="submit" className="btn btn-primary" disabled={submitting}>Register</button>
<Link className="btn btn-danger" to="/login">Cancel</Link>
</form>
如果电子邮件已经注册,控制台会在这种情况下成功打印错误。但是,当我尝试在用户表单上打印相同的错误时,如下所示
const {error, submitting, handleSubmit} = this.props;
永远不会打印错误。
即function two(msg){...
错误变量始终为空。有什么我做错了吗?
答案 0 :(得分:0)
首先,如果您只想onSubmit
进行验证,则应使用Submit Validation代替。
如果您想要的是异步验证,我可以在您的代码中看到两个错误。
catch((error) => { console.log('error', error.response); // you should throw an error here, for example: // throw { username: 'That username is taken' } reject(error.response) })
error
错误。你应该这样做:const { meta: { asyncValidating, touched, error }, submitting, handleSubmit } = this.props;
请参阅redux-form
文档中的this great example。