我的代码类似于文档中提供的this example。但是,我注意到asyncValidate
函数一旦从该字段取消聚焦,就会收到asyncBlurFields
数组中指定的任何字段的未定义。但是,当我从其他字段提交表单或unFocus时,它会返回正确的值。
例如,如果我有asyncBlurFields: ['username', 'firstname']
并且两个字段都有值,那么当我转到username
的值时,我会看到asyncValidate
未定义来自username
的取消焦点,但firstname
的值将会出现。如果我从firstname
取消焦点,则firstname
的值现在将是未定义的,而username
的值将会出现。提交表单时,这两个值都将出现。这似乎与issue #1834中提出的问题类似。但是,我不理解该问题中的回答。有人可以帮我提供一个例子或进一步的解释。
我正在使用版本7.0.1的redux-form和版本0.45.1的react-native。
答案 0 :(得分:2)
我已经弄明白了。这就是我的renderInput()
现在的样子。这里重要的是onBlur=...
renderInput({
input,
label,
type,
meta: { asyncValidating, touched, error, active }
}) {
return (
<Item>
<Input
placeholder={label}
{...input}
type={type}
onBlur={() => input.onBlur(input.value)}
/>
</Item>
);
}