Redux Forms中有没有一种方法可以让代码验证表单?

问题描述:

当表单处于原始状态时,我的代码在提交时进行验证时出现问题。有没有办法让表单验证?Redux Forms中有没有一种方法可以让代码验证表单?

是的,如果你使用jQuery,您可以创建使用的表单输入CSS选择像下面

var __inputListener__ = $("input[name=firstName]).click(function (e) {checkString(e.target.value);}); 

function checkString(string) { 
    //Run string validation here 
    if (true) 
    return true; 
    else 
    return false; 
} 

注意事件侦听器,我不知道这是e.target.value将返回值,你可能需要console.log(e)才能获得e的数组,并查看它的位置。你只要重复这一过程,你要多少投入检查等

编辑: 忘了提,你的意思是SET事件侦听器你想它来听元素已创建。

+0

马特,我的道歉,但这个问题是关于终极版形式... –

试试下面的代码:

componentDidMount() { 
    this.props.touch('username', 'email', 'age') // pass names of input fields 
}