对于asyncBlurFields

时间:2017-07-23 05:54:08

标签: react-native redux-form react-redux-form

我的代码类似于文档中提供的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。

1 个答案:

答案 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>
  );
}