Reactjs 如何在不同的操作中将不同的错误添加到redux表单字段
我的redux表单有两个动作,一个是onclick,我只需要验证一个字段,第二个动作是submit。我怎样才能做到这一点Reactjs 如何在不同的操作中将不同的错误添加到redux表单字段,reactjs,redux,redux-form,Reactjs,Redux,Redux Form,我的redux表单有两个动作,一个是onclick,我只需要验证一个字段,第二个动作是submit。我怎样才能做到这一点 class BLoginForm extends React.PureComponent{ render(){ const { handleSubmit, pristine, reset, submitting, onSubmit, openForgotForm } = this.props; return ( <FormCon>
class BLoginForm extends React.PureComponent{
render(){
const { handleSubmit, pristine, reset, submitting, onSubmit, openForgotForm } = this.props;
return (
<FormCon>
<form onSubmit = { handleSubmit(onSubmit) }>
<Field name = "username" type = "text" component = { BInputPhone } label = "Email or Mobile number" />
<Field name = "password" type = "password" component = { BInput } label = "Password" />
<a onClick = { openForgotForm } >forgot</a>
<div>
<BPrimaryBtn type = "submit" disabled = { submitting }>LOGIN</BPrimaryBtn>
</div>
</form>
</FormCon>
);
}
类blog.PureComponent{
render(){
const{handleSubmit,pristine,reset,submit,onSubmit,openForgotForm}=this.props;
返回(
忘记
登录
);
}
}为了理解,我有3种不同的形式
function submitForms() {
dispatch(submit('FirstOne')) // First form
dispatch(submit('secondOne')) // Second form
dispatch(submit('thirdOne')) // Thrid form
}
<Button type="button" onClick={ submitForms } />
我可以补充一点,如果您只想验证表单的fews字段,您可以创建一个简单的验证
const required = value => (value ? undefined : 'Required')
并将其添加到您的字段中作为
<Field {...props}
validate={required}
</Field>
我的意思是我有一个表单和两个按钮,两个按钮负责执行两个不同的任务,两个按钮都将在一些I/o调用之前执行一些基本验证。单击“忘记”,我必须进行验证,提交时,验证由redux表单本身负责。我不理解。您的验证是“重复表单验证”吗?或者其他Redux海关行动验证?单击“忘记”,我想进行一些自定义验证
<Field {...props}
validate={required}
</Field>