Redux形式,为什么asyncBlurFields在keydown中而不是onblur调用API?

时间:2019-03-07 03:19:39

标签: react-redux

我在redux格式asyncblurfield上遇到问题。

我有3个文本字段,格式如下:[MissionName],[MissionDescription],[TrackerID]

每当用户输入TrackerID并转到下一个输入字段时。它将调用API来检查TrackerID的有效性。

这是我的问题。当用户在任何这些输入字段中输入值时,它将在按下按键时调用API。

这是我的代码:

const reduxFormState = {
  form: 'createMission',
  destroyOnUnmount: false,
  forceUnregisterOnUnmount: true,
  asyncValidate: checkTrackerID,
  asyncBlurFields: ['trackerID'],
  persistentSubmitErrors: false,
  validate(values, props) {
    const {
      formMeta
    } = props;
    const __ = props.gettext;
    const errors = {};

    if (values.missionName === '' && formMeta.missionName && formMeta.missionName.touched) {
      errors.missionName = __('This field may not be blank');
    }
    return errors;
  },
  onSubmitSuccess(result, dispatch, props) {
    const {
      values
    } = props;
    const {
      mission
    } = result;
    const missionName = mission.mission.code;
    const __ = props.gettext;
    const notificationPayload = {
      untoActionTitle: 'View',
      undoAction: {
        type: 'GO_TO_MISSION',
        link: `missions/detail/${mission.mid}`
      }
    };

    if (values.createAnother) {
      props.initialize({
        template: values.template,
        missionName: '',
        missionDescription: '',
        trackerID: '',
        follow: true,
        createAnother: true
      });
    } else {
      dispatch(reset('createMission'));
      dispatch(closeCreateMissionDialog());
      dispatch(resetNewMission());
    }

    dispatch(addNotification(sprintf(__('Mission "%s" has been successfully created'), missionName), notificationPayload));
  }
};

0 个答案:

没有答案